Core without documents: no slugs; a node's top; targets by titles from the library root

The model has no slug any more (field, ops, canonical row, slugFor, freeSlug, RESERVED,
findDoc). The child of the root a node is under is a derived relation, topOf (docOf and
documents stay as deprecated aliases for the UI until step 2); ancestorsInDoc becomes
ancestorsBelowRoot. Slug keys and a target's old `doc` in stored libraries are ignored.

A node target's path is the titles down from the library root; `rel` marks a path read
below a top (a file being imported, what the agent or a person typed). Where two sections
share a title, the one the link is written in wins. The text format writes /Top title/…,
and ./… inside the exported subtree. The agent may give a node id as a target.

renderContext renders the top's outline in an <outline> tag, and steps down the focus
path when even titles are over budget. Prompts, the reviewer and the scanner speak of
the library, trees and tops; the scanner's unit is the top, with the same behaviour
(scripts/linkEval.ts gives identical metrics).

src/core/library.ts keeps a slug-free shim for the UI's document features (names made
from titles) until step 2 removes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-16 23:32:08 -05:00
1 parent 626dc19e1b
commit 44d2e437eb
32 files changed
+634 -577

No files matched your search

+11 -11
View File
@@ -9,7 +9,7 @@ import { tmpdir } from "node:os";
import { join, relative } from "node:path";
import { describe, expect, it } from "vitest";
import { LibraryStore } from "../server/library";
import { Doc, descendants, findDoc, isStale, type NodeId } from "../src/core/model";
import { Doc, descendants, isStale, tops, type NodeId } from "../src/core/model";
import { at, history, mergeBranch, revertDocTo, revertTo, verifyHistory } from "../src/core/repo";
const temp = () => mkdtempSync(join(tmpdir(), "ie-migrate-"));
@@ -86,11 +86,11 @@ describe("migration from the per-document layout", () => {
const lib = store.main;
const snap = lib.snap();
// One library: the first document first, then most recently changed first, each under its old id as slug.
// One library: the first document first, then most recently changed first.
expect(snap.library).toBe(true);
expect(store.list().map((d) => d.slug)).toEqual(["infinite-expand", "tides", "tides-copy"]);
for (const [id, old] of [["infinite-expand", first], ["tides", tides], ["tides-copy", copy]] as const) {
const node = findDoc(snap, id)!;
expect(store.list().map((d) => d.title)).toEqual(["Infinite Expand", "The tides", "The tides (copy)"]);
const [nFirst, nTides, nCopy] = tops(snap);
for (const [node, old] of [[nFirst, first], [nTides, tides], [nCopy, copy]] as const) {
expect(lib.shape(snap, node)).toBe(old.shape());
// Exactly what was stale before is stale now (the first document's edits left its root out of date).
const was = old.snap();
@@ -98,9 +98,9 @@ describe("migration from the per-document layout", () => {
}
expect(isStale(snap, snap.root)).toBe(false);
// Kept documents keep their node ids, so anchors and conflict records still point at them.
expect(findDoc(snap, "infinite-expand")).toBe(first.snap().root);
expect(findDoc(snap, "tides")).toBe(tides.snap().root);
expect(findDoc(snap, "tides-copy")).not.toBe(copy.snap().root);
expect(nFirst).toBe(first.snap().root);
expect(nTides).toBe(tides.snap().root);
expect(nCopy).not.toBe(copy.snap().root);
expect(lib.conflicts().filter((c) => c.status === "open").map((c) => c.node)).toEqual([one]);
expect(snap.nodes[one].pinned).toBe(true);
@@ -119,7 +119,7 @@ describe("migration from the per-document layout", () => {
expect(() => revertTo(lib, humanEdit)).toThrow(/before the library existed/);
revertDocTo(lib, humanEdit, first.snap().root);
expect(lib.snap().nodes[one].title).toBe("One");
expect(lib.shape(lib.snap(), findDoc(lib.snap(), "tides")!)).toBe(tides.shape());
expect(lib.shape(lib.snap(), nTides)).toBe(tides.shape());
expect(verifyHistory(lib).mismatches).toEqual([]);
// The old directory is renamed, every byte as it was; the record says what was and was not carried.
@@ -155,8 +155,8 @@ describe("migration from the per-document layout", () => {
const logs: string[] = [];
const store = new LibraryStore(data, (m) => logs.push(m)).open();
const snap = store.main.snap();
expect(store.list().map((d) => d.slug)).toEqual(["infinite-expand"]);
expect(store.main.shape(snap, findDoc(snap, "infinite-expand")!)).toBe(main.shape());
expect(store.list().map((d) => d.title)).toEqual(["Infinite Expand"]);
expect(store.main.shape(snap, tops(snap)[0])).toBe(main.shape());
expect(readdirSync(data).filter((f) => f.endsWith(".loro"))).toEqual([]);
expect(existsSync(join(data, "notes.txt"))).toBe(true); // anything else is left alone
const flat = readdirSync(data).find((f) => f.startsWith("flat.migrated-"))!;