rushes 0.2.1 → 0.3.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,333 @@
1
+ import { lstat, opendir, realpath } from "node:fs/promises";
2
+ import { setImmediate as yieldToLoop } from "node:timers/promises";
3
+ import { extname, join, sep } from "node:path";
4
+ import { toManifestPath } from "./paths.js";
5
+ export const DEFAULT_LIMITS = { maxDepth: 8, maxExamined: 5000, maxKept: 2000, budgetMs: 3000 };
6
+ /** §20.2: audio files the scan lists. */
7
+ export const AUDIO_EXT = new Set([".wav", ".mp3", ".m4a", ".aif", ".aiff", ".flac", ".ogg", ".opus"]);
8
+ /** §20.2: video files the scan lists, offered as cuts. */
9
+ export const VIDEO_EXT = new Set([".mp4", ".mov", ".m4v", ".webm"]);
10
+ /** Folders that are never walked: the project's own, and tool clutter. */
11
+ export const SKIPPED_FOLDERS = new Set(["node_modules", ".rushes", "proxies", "screenshots", "exports"]);
12
+ /** Let the event loop breathe this often, so a server using the scan stays responsive. */
13
+ const YIELD_EVERY = 200;
14
+ const VOICE_WORDS = new Set(["vo", "voice", "voiceover", "narration", "narrator", "vox", "speech", "dub", "read"]);
15
+ const MUSIC_WORDS = new Set(["bed", "music", "score", "track", "song", "theme"]);
16
+ const SFX_WORDS = new Set(["sfx", "fx", "foley", "whoosh", "hit", "riser", "impact"]);
17
+ const VERSION_WORD = /^v\d+[a-z]?$/;
18
+ function isInside(realRoot, real) {
19
+ return real === realRoot || real.startsWith(realRoot.endsWith(sep) ? realRoot : realRoot + sep);
20
+ }
21
+ /** Plain code-unit order, so the walk is the same on every machine and locale. */
22
+ function byName(a, b) {
23
+ return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
24
+ }
25
+ /**
26
+ * Reads at most `max` entries of a folder, so a folder with a hundred thousand
27
+ * entries is never loaded in one go. The order the file system gives them in is
28
+ * arbitrary, so the caller sorts what came back.
29
+ */
30
+ async function readSome(dir, max) {
31
+ const handle = await opendir(dir);
32
+ const out = [];
33
+ try {
34
+ while (out.length < max) {
35
+ const entry = await handle.read();
36
+ if (entry === null)
37
+ break;
38
+ out.push(entry);
39
+ }
40
+ }
41
+ finally {
42
+ await handle.close().catch(() => undefined);
43
+ }
44
+ return out;
45
+ }
46
+ /**
47
+ * Walks `root` within the limits, level by level, siblings in sorted order.
48
+ * Symlinks are skipped. Never reads contents. Stops (not complete) once
49
+ * `signal` aborts, checked before each folder is read. Rejects if `root` does not exist
50
+ * or cannot be resolved; anything unreadable below it is skipped quietly.
51
+ */
52
+ export async function scanFolder(root, opts = {}) {
53
+ const limits = { ...DEFAULT_LIMITS, ...opts.limits };
54
+ const now = opts.now ?? Date.now;
55
+ const skip = opts.skip;
56
+ const signal = opts.signal;
57
+ const started = now();
58
+ const realRoot = await realpath(root);
59
+ const files = [];
60
+ let examined = 0;
61
+ let complete = true;
62
+ let sinceYield = 0;
63
+ const overBudget = () => now() - started >= limits.budgetMs;
64
+ let level = [""];
65
+ let depth = 0;
66
+ walk: while (level.length > 0) {
67
+ const next = [];
68
+ for (const relDir of level) {
69
+ // Checked between folder reads: a closing server stops the walk here, not 5,000 entries later.
70
+ if (overBudget() || signal?.aborted) {
71
+ complete = false;
72
+ break walk;
73
+ }
74
+ const absDir = relDir === "" ? realRoot : join(realRoot, ...relDir.split("/"));
75
+ let entries;
76
+ try {
77
+ // A real folder can still resolve outside the root (a bind mount, say): check it.
78
+ if (relDir !== "" && !isInside(realRoot, await realpath(absDir)))
79
+ continue;
80
+ // One more than the examined limit still allows: enough to know there was more.
81
+ entries = await readSome(absDir, limits.maxExamined - examined + 1);
82
+ }
83
+ catch {
84
+ continue; // gone, or unreadable
85
+ }
86
+ entries.sort(byName);
87
+ for (const entry of entries) {
88
+ if (examined >= limits.maxExamined || overBudget()) {
89
+ complete = false;
90
+ break walk;
91
+ }
92
+ examined++;
93
+ if (++sinceYield >= YIELD_EVERY) {
94
+ sinceYield = 0;
95
+ await yieldToLoop();
96
+ }
97
+ const name = entry.name;
98
+ const rel = relDir === "" ? name : `${relDir}/${name}`;
99
+ // Some drives (network, FUSE) list names without types: then the file system is asked.
100
+ let isLink = entry.isSymbolicLink();
101
+ let isDir = entry.isDirectory();
102
+ let isPlain = entry.isFile();
103
+ if (!isLink && !isDir && !isPlain) {
104
+ try {
105
+ const info = await lstat(join(absDir, name));
106
+ isLink = info.isSymbolicLink();
107
+ isDir = info.isDirectory();
108
+ isPlain = info.isFile();
109
+ }
110
+ catch {
111
+ continue; // vanished mid-scan
112
+ }
113
+ }
114
+ if (isLink)
115
+ continue; // never followed, never listed
116
+ if (isDir) {
117
+ if (name.startsWith(".") || SKIPPED_FOLDERS.has(name.toLowerCase()))
118
+ continue;
119
+ if (skip?.(rel))
120
+ continue;
121
+ if (depth < limits.maxDepth)
122
+ next.push(rel);
123
+ continue;
124
+ }
125
+ if (!isPlain)
126
+ continue;
127
+ if (name.startsWith("."))
128
+ continue; // hidden files, such as macOS "._" companions
129
+ const ext = extname(name).toLowerCase();
130
+ const isAudio = AUDIO_EXT.has(ext);
131
+ if (!isAudio && !VIDEO_EXT.has(ext))
132
+ continue;
133
+ if (skip?.(rel))
134
+ continue;
135
+ let stat;
136
+ try {
137
+ stat = await lstat(join(absDir, name));
138
+ }
139
+ catch {
140
+ continue; // vanished mid-scan
141
+ }
142
+ if (!stat.isFile())
143
+ continue;
144
+ if (files.length >= limits.maxKept) {
145
+ complete = false;
146
+ break walk;
147
+ }
148
+ const abs = join(absDir, name);
149
+ files.push({
150
+ path: toManifestPath(realRoot, abs),
151
+ abs,
152
+ kind: isAudio ? kindOf(rel) : "cut",
153
+ folder: relDir,
154
+ size: stat.size,
155
+ modified: stat.mtimeMs,
156
+ duration: null,
157
+ });
158
+ }
159
+ }
160
+ level = next;
161
+ depth++;
162
+ }
163
+ return { files, complete, examined };
164
+ }
165
+ /**
166
+ * The words of a name: lower-cased, split on non-letters and camel case, with
167
+ * a version word such as "v20" or "v20J" kept whole. Digits are not words.
168
+ */
169
+ export function wordsOf(text) {
170
+ const words = [];
171
+ // NFKD, then drop the accents: "Thème" and "Theme", NFC or NFD, read alike.
172
+ const plain = text.normalize("NFKD").replace(/\p{M}/gu, "");
173
+ for (const chunk of plain.split(/[^\p{L}\p{N}]+/u)) {
174
+ if (chunk === "")
175
+ continue;
176
+ if (VERSION_WORD.test(chunk.toLowerCase())) {
177
+ words.push(chunk.toLowerCase());
178
+ continue;
179
+ }
180
+ for (const run of chunk.split(/[^\p{L}]+/u)) {
181
+ if (run === "")
182
+ continue;
183
+ const parts = run
184
+ .replace(/(\p{Ll})(\p{Lu})/gu, "$1 $2")
185
+ .replace(/(\p{Lu}+)(\p{Lu}\p{Ll})/gu, "$1 $2")
186
+ .split(" ");
187
+ for (const part of parts)
188
+ if (part !== "")
189
+ words.push(part.toLowerCase());
190
+ }
191
+ }
192
+ return words;
193
+ }
194
+ function kindOfWord(word) {
195
+ if (VOICE_WORDS.has(word))
196
+ return "voice";
197
+ if (MUSIC_WORDS.has(word))
198
+ return "music";
199
+ if (SFX_WORDS.has(word))
200
+ return "sfx";
201
+ return null;
202
+ }
203
+ function withoutExtension(path) {
204
+ const ext = extname(path);
205
+ return ext === "" ? path : path.slice(0, -ext.length);
206
+ }
207
+ /**
208
+ * The kind a path suggests, from the nearest folder name or file-name word
209
+ * (§20.3). The file's own name is nearest, then its folder, then the folder
210
+ * above. Video files are cuts; an audio file with no match is "other".
211
+ */
212
+ export function kindOf(relPath) {
213
+ const normal = relPath.split("\\").join("/");
214
+ if (VIDEO_EXT.has(extname(normal).toLowerCase()))
215
+ return "cut";
216
+ const parts = withoutExtension(normal).split("/");
217
+ for (let i = parts.length - 1; i >= 0; i--) {
218
+ for (const word of wordsOf(parts[i])) {
219
+ const kind = kindOfWord(word);
220
+ if (kind)
221
+ return kind;
222
+ }
223
+ }
224
+ return "other";
225
+ }
226
+ const HOUR = 3600e3;
227
+ /** "12 min", "3 hours": the nearest minute, or the nearest hour once it is an hour or more. */
228
+ function spanText(ms) {
229
+ const minutes = Math.round(ms / 60e3);
230
+ if (minutes < 60)
231
+ return `${minutes} min`;
232
+ const hours = Math.round(minutes / 60);
233
+ return hours === 1 ? "1 hour" : `${hours} hours`;
234
+ }
235
+ function seconds(value) {
236
+ return `${value.toFixed(1)} s`;
237
+ }
238
+ /** §20.4's scoring table for one audio candidate. `commonWords` are the words most files share. */
239
+ export function scoreCandidate(file, anchor, commonWords) {
240
+ let score = 0;
241
+ const reasons = [];
242
+ // Length. Sound effects are short passes, so they get none.
243
+ const d = anchor.duration;
244
+ let lengthScored = false;
245
+ if (file.kind !== "sfx" && file.duration !== null && d !== null && d > 0) {
246
+ const off = Math.abs(file.duration - d) / d;
247
+ if (off <= 0.02) {
248
+ score += 3;
249
+ reasons.push(`same length as the cut (${seconds(file.duration)} vs ${seconds(d)})`);
250
+ lengthScored = true;
251
+ }
252
+ else if (off <= 0.1) {
253
+ score += 2;
254
+ reasons.push("close to the cut's length");
255
+ lengthScored = true;
256
+ }
257
+ else if (off <= 0.25) {
258
+ score += 1;
259
+ reasons.push("in the region of the cut's length");
260
+ lengthScored = true;
261
+ }
262
+ }
263
+ if (!lengthScored && file.duration !== null && file.duration < 15 && (file.kind === "voice" || file.kind === "other")) {
264
+ reasons.push(`a short line (${Math.round(file.duration)} s)`);
265
+ }
266
+ // Made around the same time as the cut.
267
+ const delta = file.modified - anchor.modified; // negative: made before the cut
268
+ if (delta >= -6 * HOUR && delta <= 1 * HOUR) {
269
+ score += 2;
270
+ reasons.push(timeReason(delta));
271
+ }
272
+ else if (delta >= -24 * HOUR && delta < -6 * HOUR) {
273
+ score += 1;
274
+ reasons.push(timeReason(delta));
275
+ }
276
+ // Name words the file and the cut share, ignoring words every file has.
277
+ const fileWords = new Set(wordsOf(withoutExtension(file.path)));
278
+ const shared = [];
279
+ for (const word of new Set(anchor.words)) {
280
+ if (word.length < 2 || VERSION_WORD.test(word) || commonWords.has(word))
281
+ continue;
282
+ if (fileWords.has(word))
283
+ shared.push(word);
284
+ }
285
+ if (shared.length > 0) {
286
+ const used = shared.slice(0, 2);
287
+ score += used.length;
288
+ reasons.push(`name shares ${used.map((w) => `“${w}”`).join(" and ")}`);
289
+ }
290
+ // The same version word.
291
+ // A version word every file carries tells the cuts nothing apart, so it weighs nothing.
292
+ const version = anchor.words.find((w) => VERSION_WORD.test(w) && fileWords.has(w) && !commonWords.has(w));
293
+ if (version) {
294
+ score += 2;
295
+ reasons.push(`same version (${version})`);
296
+ }
297
+ return { file, score, reasons };
298
+ }
299
+ function timeReason(delta) {
300
+ const abs = Math.abs(delta);
301
+ if (Math.round(abs / 60e3) === 0)
302
+ return "made at about the same time";
303
+ return `made ${spanText(abs)} ${delta < 0 ? "before" : "after"} it`;
304
+ }
305
+ /** The words that appear in more than half of `files`' paths: they say nothing about one cut. */
306
+ export function commonWordsOf(files) {
307
+ const counts = new Map();
308
+ for (const file of files) {
309
+ for (const word of new Set(wordsOf(withoutExtension(file.path))))
310
+ counts.set(word, (counts.get(word) ?? 0) + 1);
311
+ }
312
+ const common = new Set();
313
+ for (const [word, count] of counts)
314
+ if (count > files.length / 2)
315
+ common.add(word);
316
+ return common;
317
+ }
318
+ /** Per kind (voice, music, sfx), the top candidate only when score >= 4 and it beats the runner-up by >= 1. */
319
+ export function pickCurrentSet(scored) {
320
+ const picked = {};
321
+ for (const kind of ["voice", "music", "sfx"]) {
322
+ const ranked = scored
323
+ .filter((s) => s.file.kind === kind)
324
+ .sort((a, b) => b.score - a.score || (a.file.path < b.file.path ? -1 : a.file.path > b.file.path ? 1 : 0));
325
+ const [top, runnerUp] = ranked;
326
+ if (!top || top.score < 4)
327
+ continue;
328
+ if (runnerUp && top.score - runnerUp.score < 1)
329
+ continue;
330
+ picked[kind] = top;
331
+ }
332
+ return picked;
333
+ }
@@ -0,0 +1,192 @@
1
+ // §22.4: a cut's short label, and the one-line clipping the Change Log shares. Pure and import-free,
2
+ // because the dashboard bundles this file: nothing here may pull zod or Node in, and no lookbehind
3
+ // (Safari before 16.4 can't parse one). test/core/labels.test.ts checks both, and that every
4
+ // invisible character below is written as an escape.
5
+ /** A version's short label is at most this long (§22.3). */
6
+ export const LABEL_MAX = 48;
7
+ const WORD = /[\p{L}\p{N}]/u;
8
+ const SPACE = /\s/;
9
+ const JOINER = /[_\-/]/;
10
+ // Left at the end of a cut, these read as a broken sentence, so they go before the ellipsis.
11
+ const TRAILING = /[\s,;:.\-–—(_/]+$/u;
12
+ // Code points that belong to the character before them: combining marks, the zero-width joiner
13
+ // (U+200D), variation selectors (U+FE0F), skin-tone modifiers and tag characters.
14
+ const EXTENDS = /^[\p{M}\u200d\ufe0f\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]$/u;
15
+ const REGIONAL = /^[\u{1F1E6}-\u{1F1FF}]$/u;
16
+ // A surrogate that has no partner: a paired one is a single code point under the u flag.
17
+ const LONE_SURROGATE = /[\uD800-\uDFFF]/gu;
18
+ // Control characters, including the C1 ones (U+0085), and the line and paragraph separators.
19
+ const BREAKS = /[\p{Cc}\p{Zl}\p{Zp}]+/gu;
20
+ // Format characters (bidi overrides, zero-width spaces, the word joiner, the byte-order mark) go,
21
+ // except the two joiners (U+200C, U+200D) and the tag characters, which emoji sequences need.
22
+ const INVISIBLE = /(?![\u200c\u200d\u{E0000}-\u{E007F}])\p{Cf}/gu;
23
+ // Tag characters mean something only straight after the black flag (U+1F3F4), where they spell a
24
+ // region ("England"). Anywhere else they're invisible text, so they go; a run after the flag stays.
25
+ const TAGS = /(\u{1F3F4})([\u{E0000}-\u{E007F}]*)|[\u{E0000}-\u{E007F}]+/gu;
26
+ // Text made only of these shows nothing: format characters, spaces, and the characters that draw as
27
+ // a blank (the combining grapheme joiner, the Hangul fillers, the Khmer inherent vowels, the braille blank).
28
+ const NOTHING_VISIBLE = /^[\p{Cf}\s\u034f\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]*$/u;
29
+ /**
30
+ * One clean line: a lone surrogate becomes U+FFFD, control characters and every run of whitespace
31
+ * become one space, bidi and zero-width characters go, and the ends are trimmed. Text with nothing
32
+ * visible in it comes back empty.
33
+ */
34
+ export function oneLineOf(text) {
35
+ const line = text
36
+ .replace(LONE_SURROGATE, "\uFFFD")
37
+ .replace(BREAKS, " ")
38
+ .replace(INVISIBLE, "")
39
+ .replace(TAGS, (_all, flag, tags) => (flag ? flag + tags : ""))
40
+ .replace(/\s+/g, " ")
41
+ .trim();
42
+ return NOTHING_VISIBLE.test(line) ? "" : line;
43
+ }
44
+ /** Code points grouped into what a reader sees as one character: an emoji sequence, a letter and its accents, a flag. */
45
+ function characters(points) {
46
+ const out = [];
47
+ let joined = false; // the last code point was a zero-width joiner: the next one belongs to it
48
+ let regionals = 0; // regional indicators in the last cluster (a flag is a pair)
49
+ for (const p of points) {
50
+ const last = out.length - 1;
51
+ if (last >= 0 && (joined || EXTENDS.test(p) || (REGIONAL.test(p) && regionals === 1))) {
52
+ out[last] += p;
53
+ regionals = REGIONAL.test(p) ? regionals + 1 : regionals;
54
+ }
55
+ else {
56
+ out.push(p);
57
+ regionals = REGIONAL.test(p) ? 1 : 0;
58
+ }
59
+ joined = p === "\u200d";
60
+ }
61
+ return out;
62
+ }
63
+ function lastIndex(chars, re) {
64
+ for (let i = chars.length - 1; i > 0; i--)
65
+ if (re.test(chars[i]))
66
+ return i;
67
+ return -1;
68
+ }
69
+ /**
70
+ * `text`, at most `max` characters. They're counted as code points, and a cut never falls inside
71
+ * an emoji sequence or between a letter and its accents. The cut falls at the last word boundary
72
+ * that leaves room for "…" (§22.4 (4)). A boundary is a space; in a name with none (a file name),
73
+ * an underscore, a hyphen or a slash. Only a single unbroken word is cut inside it.
74
+ */
75
+ export function clip(text, max) {
76
+ if (text.length <= max)
77
+ return text;
78
+ const points = Array.from(text);
79
+ if (points.length <= max)
80
+ return text;
81
+ // Only the start matters, so a very long note isn't grouped all the way down.
82
+ const chars = characters(points.slice(0, max + 32));
83
+ const head = [];
84
+ let used = 0;
85
+ for (const c of chars) {
86
+ const n = Array.from(c).length;
87
+ if (used + n > max - 1)
88
+ break;
89
+ head.push(c);
90
+ used += n;
91
+ }
92
+ // One character with no room for it (a base under hundreds of marks): keep its base. Marks with
93
+ // no base at all still come back as a bare ellipsis, which callers treat as nothing to show.
94
+ const base = chars.length > 0 ? Array.from(chars[0])[0] : "";
95
+ if (head.length === 0 && max > 1 && base && !EXTENDS.test(base))
96
+ return base + "…";
97
+ let cut = head.length;
98
+ const next = chars[head.length];
99
+ if (next !== undefined && !SPACE.test(next)) {
100
+ let at = lastIndex(head, SPACE);
101
+ if (at <= 0)
102
+ at = lastIndex(head, JOINER);
103
+ if (at > 0)
104
+ cut = at;
105
+ }
106
+ return head.slice(0, cut).join("").replace(TRAILING, "") + "…";
107
+ }
108
+ /** One line, clipped: how every Change Log line is stored (§22.3: 160 characters at most). */
109
+ export function oneLine(text, max) {
110
+ return clip(oneLineOf(text), max);
111
+ }
112
+ // §22.4 (3): a note's first clause ends at the first of these that comes after its first 12 characters.
113
+ const CLAUSE_ENDS = [";", ". ", " — ", " ("];
114
+ const CLAUSE_MIN = 12;
115
+ /** How many UTF-16 units the first `n` code points of `text` take up. */
116
+ function unitsOfFirst(text, n) {
117
+ let units = 0;
118
+ let seen = 0;
119
+ for (const ch of text) {
120
+ if (seen++ >= n)
121
+ break;
122
+ units += ch.length;
123
+ }
124
+ return units;
125
+ }
126
+ // `skipped` is how many code points were stripped from the note's start (a "v6: " or a
127
+ // "(batch b_1): "): the 12 count from the note as written, so "v1: first pass; rough" still ends at
128
+ // "first pass".
129
+ function firstClause(text, skipped) {
130
+ const from = unitsOfFirst(text, Math.max(0, CLAUSE_MIN - skipped));
131
+ let end = text.length;
132
+ for (const sep of CLAUSE_ENDS) {
133
+ const i = text.indexOf(sep, from);
134
+ if (i >= 0 && i < end)
135
+ end = i;
136
+ }
137
+ return text.slice(0, end).trim();
138
+ }
139
+ /** The file's name without its folder or extension, on one line: "renders/lumen_v6.mp4" gives "lumen_v6". */
140
+ function fileStem(file) {
141
+ const name = file.split(/[\\/]/).pop() ?? "";
142
+ const dot = name.lastIndexOf(".");
143
+ return oneLineOf(dot > 0 ? name.slice(0, dot) : name);
144
+ }
145
+ // A leading "v6" is this cut's own id when it's followed by ":", ",", a dash, a full stop and a
146
+ // space, the end, or a "(batch …)": "v6.5 slower" and "v60: x" are not.
147
+ // Built once per version number: a backfill reads thousands of cuts (Task 3 review, minor 7).
148
+ const LEADING_IDS = new Map();
149
+ function leadingId(digits) {
150
+ const n = digits.replace(/^0+/, "") || "0";
151
+ let re = LEADING_IDS.get(n);
152
+ if (!re) {
153
+ if (LEADING_IDS.size >= 2000)
154
+ LEADING_IDS.clear();
155
+ re = buildLeadingId(n);
156
+ LEADING_IDS.set(n, re);
157
+ }
158
+ return re;
159
+ }
160
+ function buildLeadingId(n) {
161
+ return new RegExp(`^v0*${n}(?![\\p{L}\\p{N}])(?:(?:\\s*[:,\\-–—]|\\.(?=\\s|$))[\\s:,.\\-–—]*|\\s*$|\\s+(?=\\(batch\\b))`, "iu");
162
+ }
163
+ // Something to show: not empty, and not a bare ellipsis left by a cut that had nothing before it.
164
+ const usable = (s) => s !== "" && s !== "…";
165
+ /**
166
+ * §22.4: the version's own label when it has one. Otherwise its note's first clause, without a
167
+ * leading "v6:" that repeats the id or a "(batch b_1):". Otherwise the file's name, then the id.
168
+ * Always one line, never over LABEL_MAX characters, never empty.
169
+ */
170
+ export function shortLabel(v) {
171
+ const own = clip(oneLineOf(v.label ?? ""), LABEL_MAX);
172
+ if (usable(own))
173
+ return own;
174
+ const note = oneLineOf(v.note ?? "");
175
+ let text = note;
176
+ const n = /^v(\d+)$/i.exec(v.id)?.[1];
177
+ if (n !== undefined)
178
+ text = text.replace(leadingId(n), "");
179
+ text = text.replace(/^\(batch\b[^)]*\)\s*:?\s*/i, "");
180
+ const skipped = Array.from(note.slice(0, note.length - text.length)).length;
181
+ text = firstClause(text, skipped);
182
+ if (WORD.test(text)) {
183
+ const fromNote = clip(text, LABEL_MAX);
184
+ if (usable(fromNote))
185
+ return fromNote;
186
+ }
187
+ const stem = clip(fileStem(v.file), LABEL_MAX);
188
+ if (usable(stem))
189
+ return stem;
190
+ const id = clip(oneLineOf(v.id), LABEL_MAX);
191
+ return usable(id) ? id : "Untitled";
192
+ }