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
54 lines
2.9 KiB
TypeScript
54 lines
2.9 KiB
TypeScript
/** The seed tree against the prompt it was grown from: the first tree of a new library. */
|
|
import { readFileSync } from "node:fs";
|
|
import { describe, expect, it } from "vitest";
|
|
import { Doc, descendants, isStale, notesOf, sections } from "../src/core/model";
|
|
import { verifyHistory } from "../src/core/repo";
|
|
import { SEED_TITLE, writeSeed } from "../src/core/seed";
|
|
import { overlaps, sentences, wordCount } from "../src/core/text";
|
|
import { seed } from "../src/seed/tree";
|
|
|
|
const prompt = readFileSync(new URL("../src/seed/prompt.txt", import.meta.url), "utf8");
|
|
const doc = Doc.library("seed");
|
|
const first = writeSeed(doc, prompt, seed);
|
|
const snap = doc.snap();
|
|
const root = snap.nodes[first];
|
|
|
|
describe("seed tree", () => {
|
|
it("keeps the prompt verbatim as the text of its top, written by a human and pinned, as a section of the library", () => {
|
|
expect(root.body).toBe(prompt.trim());
|
|
expect(root).toMatchObject({ by: "human", pinned: true, parent: snap.root, title: SEED_TITLE });
|
|
expect(snap.library).toBe(true);
|
|
});
|
|
|
|
it("traces every sentence of the prompt to at least one top-level section", () => {
|
|
const anchors = sections(snap, first).flatMap((id) => snap.nodes[id].anchors);
|
|
const all = sentences(root.body);
|
|
expect(all.length).toBeGreaterThan(30);
|
|
const uncovered = all.filter((s) => !anchors.some((a) => overlaps(s, [a.start, a.end])));
|
|
expect(uncovered.map(([s, e]) => root.body.slice(s, e))).toEqual([]);
|
|
// And the anchors really are the prompt's own words.
|
|
for (const a of anchors) expect(a.text).toBe(a.quote);
|
|
});
|
|
|
|
it("is three sections deep with notes in every form, some nested", () => {
|
|
const depth = (id: string): number => 1 + Math.max(0, ...sections(snap, id as never).map(depth));
|
|
expect(depth(first) - 1).toBeGreaterThanOrEqual(3);
|
|
const notes = descendants(snap, first).map((id) => snap.nodes[id]).filter((n) => n.kind === "note");
|
|
expect(new Set(notes.map((n) => n.form))).toEqual(new Set(["gloss", "note", "passage"]));
|
|
expect(notes.filter((n) => snap.nodes[n.parent!].kind === "note").length).toBeGreaterThanOrEqual(3);
|
|
for (const n of notes.filter((n) => n.form === "gloss")) expect(wordCount(n.body)).toBeLessThanOrEqual(15);
|
|
for (const n of Object.values(snap.nodes)) {
|
|
const spans = notesOf(snap, n.id).flatMap((id) => snap.nodes[id].anchors.map((a) => [a.start, a.end] as [number, number]));
|
|
for (let i = 0; i < spans.length; i++) for (let j = i + 1; j < spans.length; j++) expect(overlaps(spans[i], spans[j])).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("starts with nothing stale and a history that verifies", () => {
|
|
expect(Object.keys(snap.nodes).filter((id) => isStale(snap, id as never))).toEqual([]);
|
|
const v = verifyHistory(doc);
|
|
expect(v.mismatches).toEqual([]);
|
|
// The library, the tree's top, and one commit per section under it.
|
|
expect(v.checked).toBe(seed.length + 2);
|
|
});
|
|
});
|