Translate Project Management and add its tests and guide

- Every interface string of Project Management goes through the catalog: 539 new rows with fr, ja, and zh-CN.
- Storage and model messages use a local message() marker and stay free of host imports. The interface translates them.
- A board renders again when the language changes. Dates use the interface language.
- Fix: the ribbon button waits for the feature switches at startup, and the settings code loads no feature module.
- Add six smoke tests: board state, cards, menus, drag and drop, views, and language.
- Add docs/guides/project-management.md and UI-060. Update the user, plugin, SDK, host, development, and interface docs and CLAUDE.md.
- Name the fake board view of tree/renameUndo "Board fixture", because the native Project Management button is now in the ribbon.
This commit is contained in:
Knotty Wyvern
2026-10-29 21:53:09 -07:00
parent e66f089176
commit 956ead818b
53 changed files with 2510 additions and 867 deletions
+82 -104
View File
@@ -1,5 +1,5 @@
import { readTask, editTask, adoptNote, split } from "../storage/notes.ts";
import { createCard, readCards, cardOrigin, cardPath, migrateCards, parseCard, prepareCards } from "../storage/cards.ts";
import { createCard, readCards, cardOrigin, cardPath, fileIssue, migrateCards, parseCard, prepareCards } from "../storage/cards.ts";
import { cardsFolder, cardsMarker, isHiddenCard, readOptional, saveDocument, storageRoot } from "../storage/persistence.ts";
import { deletedCardsPath, readDeletedCards, recordCardDeletion } from "../storage/deleted-cards.ts";
import { mapConcurrent, markdownPaths, readSources } from "../storage/scan.ts";
@@ -14,6 +14,7 @@ import {
createBoard,
} from "../storage/catalog.ts";
import { migrateStorage } from "../storage/migration.ts";
import { format, message } from "../storage/message.ts";
import {
BoardStore,
boardDocument,
@@ -32,7 +33,10 @@ export interface TaskStoreOptions {
legacy?: boolean;
}
const message = (error: unknown) => error instanceof Error ? error.message : String(error);
const errorMessage = (error: unknown) => error instanceof Error ? error.message : String(error);
/** The issue of a task ID that more than one note uses. `adopt()` looks for this issue. */
const duplicateTaskIssue = (id: string) =>
format(message("Duplicate task ID {id}: resolve the copied notes before editing them."), { id });
/** The files of `.runestone/pm/` that the hidden mode reads, with the problem of each file. */
interface HiddenState {
@@ -78,7 +82,7 @@ export class TaskStore {
}
private check() {
if (this.disposed)
throw new Error("The Project Management view is closed. Reopen it before saving.");
throw new Error(message("The Project Management view is closed. Reopen it before saving."));
}
/** Read all Project Management data again. */
async reload(): Promise<void> {
@@ -99,7 +103,7 @@ export class TaskStore {
for (const path of paths) this.acceptCard(state, path, sources.get(path)!, previous.get(path));
}
} catch (error) {
state.cardsError = message(error);
state.cardsError = errorMessage(error);
}
await Promise.all([this.readHiddenCatalog(state), this.readHiddenLabels(state), this.readHiddenDeleted(state)]);
this.check();
@@ -148,12 +152,12 @@ export class TaskStore {
}
private acceptCard(state: HiddenState, path: string, result: { source?: string; error?: string }, cached?: Task) {
try {
if (result.error || result.source === undefined) throw new Error(result.error ?? "The card is unavailable.");
if (result.error || result.source === undefined) throw new Error(result.error ?? message("The card is unavailable."));
state.cards.set(path, cached?.source === result.source ? cached : parseCard(path, result.source));
state.cardIssues.delete(path);
} catch (error) {
state.cards.delete(path);
state.cardIssues.set(path, message(error));
state.cardIssues.set(path, errorMessage(error));
}
}
private async readHiddenCatalog(state: HiddenState) {
@@ -162,25 +166,25 @@ export class TaskStore {
state.catalog = { source: catalog.source, boards: managedDocuments(catalog.value, catalog.source ?? ""), error: "" };
} catch (error) {
// Do not expose boards as writable when hidden storage cannot be read.
state.catalog = { source: null, boards: [], error: message(error) };
state.catalog = { source: null, boards: [], error: errorMessage(error) };
}
}
private async readHiddenLabels(state: HiddenState) {
try { state.labels = { snapshot: await this.labels.read(), error: "" }; }
catch (error) { state.labels = { error: message(error) }; }
catch (error) { state.labels = { error: errorMessage(error) }; }
}
private async readHiddenDeleted(state: HiddenState) {
try { state.deleted = { ids: new Set((await readDeletedCards(this.workspace)).ids), error: "" }; }
catch (error) { state.deleted = { ids: new Set(), error: message(error) }; }
catch (error) { state.deleted = { ids: new Set(), error: errorMessage(error) }; }
}
/** Make the public fields from the hidden files. One invalid card file hides all cards, as in the legacy mode. */
private publishHidden() {
const state = this.hidden!;
const issues: string[] = [...[...state.cardIssues].map(([path, issue]) => `${path}: ${issue}`)];
if (state.cardsError) issues.push("Hidden cards: " + state.cardsError);
if (state.catalog.error) issues.push("Hidden Project Management storage: " + state.catalog.error);
if (state.labels.error) issues.push("Saved labels: " + state.labels.error);
if (state.deleted.error) issues.push("Deleted cards: " + state.deleted.error);
const issues: string[] = [...[...state.cardIssues].map(([path, issue]) => fileIssue(path, issue))];
if (state.cardsError) issues.push(format(message("Hidden cards: {error}"), { error: state.cardsError }));
if (state.catalog.error) issues.push(format(message("Hidden Project Management storage: {error}"), { error: state.catalog.error }));
if (state.labels.error) issues.push(format(message("Saved labels: {error}"), { error: state.labels.error }));
if (state.deleted.error) issues.push(format(message("Deleted cards: {error}"), { error: state.deleted.error }));
this.labels.load(state.labels.snapshot, state.labels.error);
const blocked = !!(state.cardsError || state.cardIssues.size || state.deleted.error);
this.tasks = blocked ? [] : [...state.cards.values()]
@@ -191,7 +195,7 @@ export class TaskStore {
if (this.board.reference) {
this.board.load(this.boards.find((board) => board.id === this.board.reference!.id));
if (!this.board.available)
issues.push("This board is missing, invalid, or duplicated. Task notes remain available in All tasks.");
issues.push(message("This board is missing, invalid, or duplicated. Task notes remain available in All tasks."));
}
this.issues = issues;
workspaceTasks.set(this.workspace, this.tasks);
@@ -210,16 +214,14 @@ export class TaskStore {
this.check();
try {
const result = sources.get(path)!;
if (result.error || result.source === undefined) throw new Error(result.error ?? "The file is unavailable.");
if (result.error || result.source === undefined) throw new Error(result.error ?? message("The file is unavailable."));
const source = result.source;
const cached = previous.get(path);
if (cached?.source === source) return { task: cached };
const board = boardDocument(source, path);
return board ? { board } : { task: readTask(path, source) };
} catch (error) {
return {
issue: `${path}: ${error instanceof Error ? error.message : String(error)}`,
};
return { issue: fileIssue(path, errorMessage(error)) };
}
});
for (const document of documents) {
@@ -241,17 +243,15 @@ export class TaskStore {
)
tasks.splice(tasks.indexOf(original), 1);
else
issues.push(
`The original card differs from hidden storage: ${original.path}. Preserve both versions.`,
);
issues.push(format(
message("The original card differs from hidden storage: {path}. Preserve both versions."),
{ path: original.path },
));
}
}
tasks.push(...hidden.tasks);
} catch (error) {
issues.push(
"Hidden cards: " +
(error instanceof Error ? error.message : String(error)),
);
issues.push(format(message("Hidden cards: {error}"), { error: errorMessage(error) }));
// Block legacy edits when the hidden store cannot be checked for migrated IDs.
tasks.length = 0;
}
@@ -271,17 +271,15 @@ export class TaskStore {
)
boards.splice(boards.indexOf(board), 1);
else
issues.push(
`Legacy board differs from hidden storage: ${board.path}. Preserve both versions before cleanup.`,
);
issues.push(format(
message("The legacy board differs from hidden storage: {path}. Preserve both versions before cleanup."),
{ path: board.path },
));
}
}
boards.push(...managedDocuments(catalog.value, catalog.source ?? ""));
} catch (error) {
issues.push(
"Hidden Project Management storage: " +
(error instanceof Error ? error.message : String(error)),
);
issues.push(format(message("Hidden Project Management storage: {error}"), { error: errorMessage(error) }));
// Do not expose legacy boards as writable when hidden storage cannot be read.
boards.length = 0;
}
@@ -290,8 +288,8 @@ export class TaskStore {
try {
labels = await this.labels.read();
} catch (error) {
labelError = error instanceof Error ? error.message : String(error);
issues.push("Saved labels: " + labelError);
labelError = errorMessage(error);
issues.push(format(message("Saved labels: {error}"), { error: labelError }));
}
this.check();
if (revision !== this.revision) return;
@@ -301,14 +299,11 @@ export class TaskStore {
for (const task of tasks)
counts.set(task.id, (counts.get(task.id) ?? 0) + 1);
for (const [id, count] of counts)
if (count > 1)
issues.push(
`Duplicate task ID ${id}: resolve the copied notes before editing them.`,
);
if (count > 1) issues.push(duplicateTaskIssue(id));
let deletedIds = new Set<string>();
try { deletedIds = new Set((await readDeletedCards(this.workspace)).ids); }
catch (error) {
issues.push("Deleted cards: " + (error instanceof Error ? error.message : String(error)));
issues.push(format(message("Deleted cards: {error}"), { error: errorMessage(error) }));
tasks.length = 0;
}
this.check();
@@ -321,9 +316,7 @@ export class TaskStore {
boardCounts.set(board.id, (boardCounts.get(board.id) ?? 0) + 1);
for (const [id, count] of boardCounts)
if (count > 1)
issues.push(
`Duplicate board ID ${id}: resolve the copied boards before editing them.`,
);
issues.push(format(message("Duplicate board ID {id}: resolve the copied boards before editing them."), { id }));
this.boards = boards
.filter((board) => boardCounts.get(board.id) === 1)
.sort((a, b) => a.name.localeCompare(b.name));
@@ -332,9 +325,7 @@ export class TaskStore {
this.boards.find((board) => board.id === this.board.reference!.id),
);
if (!this.board.available)
issues.push(
"This board is missing, invalid, or duplicated. Task notes remain available in All tasks.",
);
issues.push(message("This board is missing, invalid, or duplicated. Task notes remain available in All tasks."));
}
this.issues = issues;
workspaceTasks.set(this.workspace, this.tasks);
@@ -360,7 +351,7 @@ export class TaskStore {
await this.reloadFor([task.path]);
const current = this.tasks.find(item => item.id === task.id && item.path === task.path);
if (!current || current.source !== task.source)
throw new Error("The card changed or is unavailable. Refresh before deleting it.");
throw new Error(message("The card changed or is unavailable. Refresh before deleting it."));
await recordCardDeletion(this.workspace, task.id);
await this.reloadFor([deletedCardsPath]);
});
@@ -373,7 +364,7 @@ export class TaskStore {
const found = this.tasks.find(task => task.id === source.id && task.path === source.path);
if (found && !found.links?.some(link => link.taskId === targetId)) return undefined;
if (!found || found.source !== source.source)
throw new Error("A linked card changed. Refresh before removing its link.");
throw new Error(message("A linked card changed. Refresh before removing its link."));
return found;
});
for (const source of current) {
@@ -395,17 +386,15 @@ export class TaskStore {
(item) => item.id === task.id && item.path === task.path,
);
if (!current || current.source !== task.source)
throw new Error(
"The task changed or has a duplicate ID. Cancel, refresh, and review the note before saving.",
);
throw new Error(message("The task changed or has a duplicate ID. Cancel, refresh, and review the note before saving."));
const next = { ...patch };
if (Object.hasOwn(next, "listId")) {
if (this.board.archived)
throw new Error("Restore this board before moving cards.");
throw new Error(message("Restore this board before moving cards."));
const listId = next.listId ?? null;
const list = this.board.value.lists.find((list) => list.id === listId);
if (listId !== null && !list)
throw new Error("This list no longer exists. Refresh the board.");
throw new Error(message("This list no longer exists. Refresh the board."));
const previousList = this.board.listFor(task);
if (applyListStatus && listId !== (previousList?.id ?? null)) {
if (list?.status) next.status = list.status;
@@ -414,7 +403,7 @@ export class TaskStore {
const id = this.board.reference?.id;
if (id) {
if (!this.board.available)
throw new Error("The board is unavailable. Reopen it before saving.");
throw new Error(message("The board is unavailable. Reopen it before saving."));
const placement = { ...task.placements?.[id], listId };
if (
listId !== (this.board.listFor(task)?.id ?? null) ||
@@ -491,9 +480,9 @@ export class TaskStore {
return this.run(async () => {
await this.reloadFor(this.cardsInList(listId).map(task => task.path));
if (!this.board.editable || !this.board.value.lists.some((list) => list.id === listId))
throw new Error("The list is unavailable. Refresh the board.");
throw new Error(message("The list is unavailable. Refresh the board."));
if (this.issues.length)
throw new Error("Resolve workspace issues before archiving cards: " + this.issues.join(" "));
throw new Error(format(message("Resolve workspace issues before archiving cards: {issues}"), { issues: this.issues.join(" ") }));
for (const task of this.cardsInList(listId)) {
const source = editTask(task, { archived: true });
await saveDocument(this.workspace, task.path, source, task.source);
@@ -513,7 +502,7 @@ export class TaskStore {
beforeId == null
? cards.length
: cards.findIndex((card) => card.id === beforeId);
if (index < 0) throw new Error("The target card moved. Refresh the board.");
if (index < 0) throw new Error(message("The target card moved. Refresh the board."));
const id = this.board.reference?.id;
return orderBetween(
index > 0 ? cardOrder(cards[index - 1], id) : undefined,
@@ -524,30 +513,28 @@ export class TaskStore {
const path = title.trim().replaceAll("\\", "/").replace(/^\.\//, "");
if (!/\.(md|markdown|mdown)$/i.test(path)) return this.create(title, fields, "");
if (/^(?:[a-z]+:|\/)/i.test(path) || path.split("/").some(part => !part || part === "." || part === ".."))
throw new Error("Use a relative Markdown path inside this workspace.");
throw new Error(message("Use a relative Markdown path inside this workspace."));
const added = await this.adopt(path);
const task = this.tasks.find(item => item.id === added.id && item.path === added.path);
if (!task) throw new Error("The linked card is unavailable. Refresh the board.");
if (!task) throw new Error(message("The linked card is unavailable. Refresh the board."));
if (this.board.reference) await this.moveTask(task, fields.listId ?? null);
}
create(title: string, fields: TaskFields, body: string, destinationId?: string): Promise<void> {
return this.run(async () => {
if (!this.workspace.create)
throw new Error(
"This RuneStone version cannot create plugin notes. Add an existing note or install the host bridge.",
);
throw new Error(message("This RuneStone version cannot create plugin notes. Add an existing note or install the host bridge."));
if (!this.loaded) await this.reload();
++this.revision;
if (destinationId !== undefined) await this.reloadFor([catalogPath]);
const destination = destinationId === undefined ? undefined : this.boards.find(board => board.id === destinationId && !board.archived);
if (destinationId !== undefined && !destination) throw new Error("Choose an available, active board for this card.");
if (destinationId !== undefined && !destination) throw new Error(message("Choose an available, active board for this card."));
const id = destination?.id ?? this.board.reference?.id;
if (id && !destination && !this.board.available)
throw new Error("The board is unavailable. Reopen it before saving.");
throw new Error(message("The board is unavailable. Reopen it before saving."));
// Named-board creation reads the current board without a workspace scan.
await this.board.reload();
if (this.board.archived)
throw new Error("Restore this board before adding cards.");
throw new Error(message("Restore this board before adding cards."));
const targetBoard = destination?.value ?? this.board.value;
const listId =
fields.listId === undefined
@@ -558,7 +545,7 @@ export class TaskStore {
listId !== null &&
!targetBoard.lists.some((list) => list.id === listId)
)
throw new Error("This list no longer exists. Refresh the board.");
throw new Error(message("This list no longer exists. Refresh the board."));
const lastGlobalCard = this.tasks
.filter(
(task) =>
@@ -602,10 +589,10 @@ export class TaskStore {
await this.reloadFor([cardPath(parentId)]);
const parent = this.tasks.find(task => task.id === parentId);
const item = parent?.subtasks?.find(item => item.id === subtaskId);
if (!parent || !item) throw new Error("The subtask is unavailable. Refresh the board.");
if (!parent || !item) throw new Error(message("The subtask is unavailable. Refresh the board."));
if (item.taskId) {
const target = this.tasks.find(task => task.id === item.taskId);
if (!target) throw new Error("The subtask card is unavailable. Refresh the board.");
if (!target) throw new Error(message("The subtask card is unavailable. Refresh the board."));
return target;
}
// A stable ID lets a retry recover after the child saves but the parent fails.
@@ -637,7 +624,7 @@ export class TaskStore {
removeFromBoard(task: Task): Promise<void> {
const id = this.board.reference?.id;
if (!id)
return Promise.reject(new Error("Open a board before removing a card."));
return Promise.reject(new Error(message("Open a board before removing a card.")));
const placements = { ...task.placements };
delete placements[id];
return this.save(task, { placements });
@@ -647,8 +634,8 @@ export class TaskStore {
await this.reloadFor([task.path]);
const destination = this.boards.find(board => board.id === destinationId);
if (!destination || destination.archived || (listId !== null && !destination.value.lists.some(list => list.id === listId)))
throw new Error("The destination board or list is unavailable. Refresh the board.");
if (this.board.reference && (!this.board.available || this.board.archived)) throw new Error("Open an available, active board before moving a card.");
throw new Error(message("The destination board or list is unavailable. Refresh the board."));
if (this.board.reference && (!this.board.available || this.board.archived)) throw new Error(message("Open an available, active board before moving a card."));
const placements = { ...task.placements };
if (this.board.reference) delete placements[this.board.reference.id];
const last = this.tasks.filter(item => item.id !== task.id && item.placements?.[destinationId]?.listId === listId).sort((a, b) => compareCards(a, b, destinationId)).at(-1);
@@ -669,21 +656,21 @@ export class TaskStore {
await this.reloadFor([task.path]);
const sourceId = this.board.reference?.id;
if (!sourceId || !this.board.available || this.board.archived)
throw new Error("Open an available, active board before moving a card.");
throw new Error(message("Open an available, active board before moving a card."));
const current = this.tasks.find(
(item) => item.id === task.id && item.path === task.path,
);
if (!current || current.source !== task.source)
throw new Error("The card changed. Cancel, refresh, and review it before moving.");
throw new Error(message("The card changed. Cancel, refresh, and review it before moving."));
if (!Object.hasOwn(current.placements ?? {}, sourceId))
throw new Error("This card no longer belongs to the source board.");
throw new Error(message("This card no longer belongs to the source board."));
if (sourceId === destinationId)
throw new Error("Choose a different destination board.");
throw new Error(message("Choose a different destination board."));
const destination = this.boards.find((board) => board.id === destinationId);
if (!destination || destination.archived)
throw new Error("The destination board is unavailable or archived. Choose another board.");
throw new Error(message("The destination board is unavailable or archived. Choose another board."));
if (listId !== null && !destination.value.lists.some((list) => list.id === listId))
throw new Error("The destination list no longer exists. Choose another list.");
throw new Error(message("The destination list no longer exists. Choose another list."));
const last = this.tasks
.filter((card) => card.id !== task.id && card.archived === task.archived &&
Object.hasOwn(card.placements ?? {}, destinationId) &&
@@ -724,9 +711,9 @@ export class TaskStore {
if (removed.size) {
await this.reloadFor([labelsPath]);
if (this.labels.source !== expected)
throw new Error("Saved labels changed. Refresh before deleting labels.");
throw new Error(message("Saved labels changed. Refresh before deleting labels."));
if (this.issues.length)
throw new Error("Resolve workspace issues before deleting labels: " + this.issues.join(" "));
throw new Error(format(message("Resolve workspace issues before deleting labels: {issues}"), { issues: this.issues.join(" ") }));
// Keep definitions until every guarded card write succeeds, so a retry is safe.
for (const task of this.tasks)
if (task.labels?.some((id) => removed.has(id))) {
@@ -751,16 +738,11 @@ export class TaskStore {
return this.run(async () => {
await this.reload();
if (this.issues.length)
throw new Error(
"Resolve the workspace issues before migration: " +
this.issues.join(" "),
);
throw new Error(format(message("Resolve the workspace issues before migration: {issues}"), { issues: this.issues.join(" ") }));
const selected = cardIds.map((id) => {
const task = this.tasks.find((task) => task.id === id);
if (!task)
throw new Error(
"A selected card is unavailable. Refresh before migration.",
);
throw new Error(message("A selected card is unavailable. Refresh before migration."));
return task;
});
const result = await migrateStorage(
@@ -779,14 +761,14 @@ export class TaskStore {
return this.run(async () => {
await this.reloadFor([catalogPath]);
if (!this.board.editable)
throw new Error("Open an available board before renaming it.");
throw new Error(message("Open an available board before renaming it."));
const reference = this.board.reference!;
if (isManagedBoard(reference.path)) {
await this.board.manage({ name });
await this.reloadFor([catalogPath]);
return;
}
if (!rename) throw new Error("Migrate this board before renaming it.");
if (!rename) throw new Error(message("Migrate this board before renaming it."));
const path = await rename({ ...reference }, name.trim());
reference.path = path;
await this.reload();
@@ -801,15 +783,13 @@ export class TaskStore {
if (!this.legacy) return this.run(() => this.adoptHidden(path));
return this.run(async () => {
if (!/\.(md|markdown|mdown)$/i.test(path))
throw new Error("Choose a Markdown note from this workspace.");
throw new Error(message("Choose a Markdown note from this workspace."));
await this.reload();
const id = this.board.reference?.id;
if (id && !this.board.available)
throw new Error(
"The board is unavailable. Reopen it before adding a note.",
);
throw new Error(message("The board is unavailable. Reopen it before adding a note."));
if (this.board.archived)
throw new Error("Restore this board before adding cards.");
throw new Error(message("Restore this board before adding cards."));
const source = await this.workspace.read(path);
let next = adoptNote(path, source);
const task = readTask(path, next)!;
@@ -817,11 +797,9 @@ export class TaskStore {
this.tasks.some(
(other) => other.id === task.id && other.path !== path,
) ||
this.issues.some((issue) =>
issue.startsWith(`Duplicate task ID ${task.id}:`),
)
this.issues.includes(duplicateTaskIssue(task.id))
)
throw new Error("Resolve this task's duplicate ID before adding it.");
throw new Error(message("Resolve this task's duplicate ID before adding it."));
if (id && !Object.hasOwn(task.placements ?? {}, id))
next = editTask(task, {
placements: {
@@ -839,23 +817,23 @@ export class TaskStore {
await saveDocument(this.workspace, path, next, source);
await this.reload();
const added = this.tasks.find(item => item.path === path);
if (!added) throw new Error("The linked card is unavailable. Refresh the board.");
if (!added) throw new Error(message("The linked card is unavailable. Refresh the board."));
return added;
});
}
private async adoptHidden(path: string): Promise<Task> {
if (!/\.(md|markdown|mdown)$/i.test(path))
throw new Error("Choose a Markdown note from this workspace.");
throw new Error(message("Choose a Markdown note from this workspace."));
const id = this.board.reference?.id;
if (id && !this.board.available)
throw new Error("The board is unavailable. Reopen it before adding a note.");
throw new Error(message("The board is unavailable. Reopen it before adding a note."));
if (this.board.archived)
throw new Error("Restore this board before adding cards.");
throw new Error(message("Restore this board before adding cards."));
let card: Task | undefined;
if (isHiddenCard(path)) {
await this.reloadFor([path]);
card = this.tasks.find(task => task.path === path);
if (!card) throw new Error("The linked card is unavailable. Refresh the board.");
if (!card) throw new Error(message("The linked card is unavailable. Refresh the board."));
} else {
const source = await this.workspace.read(path);
const note = readTask(path, source);
@@ -868,11 +846,11 @@ export class TaskStore {
await this.reloadFor([cardPath(note.id)]);
card = this.tasks.find(task => task.id === note.id);
}
if (!card) throw new Error("The linked card is unavailable. Refresh the board.");
if (!card) throw new Error(message("The linked card is unavailable. Refresh the board."));
} else {
const { doc, body, match, newline } = split(source);
if (doc.has("runestone_pm"))
throw new Error("This document already contains Project Management data and cannot become a task.");
throw new Error(message("This document already contains Project Management data and cannot become a task."));
const cardId = crypto.randomUUID();
const last = this.tasks.filter(task => task.status === "todo" && !task.archived).sort((a, b) => compareCards(a, b)).at(-1);
doc.set("runestone_pm", {