From e6d71e84de42a9ab91731c40db4276b149880c5d Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 17 Nov 2026 16:26:32 -0500 Subject: [PATCH] Links: one targetTitle for the links list and the reviewer src/ui/linker.ts titleOf and server/links/review.ts targetTitle named a target the same way (a node's label, else its path or "a note"; an article's title; a page's title or address). It lives in src/core/links.ts beside the other helpers on targets. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab --- server/links/review.ts | 5 +---- src/core/links.ts | 8 +++++++- src/ui/linker.ts | 12 +++--------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/server/links/review.ts b/server/links/review.ts index 9e83017..b32ff3e 100644 --- a/server/links/review.ts +++ b/server/links/review.ts @@ -11,9 +11,8 @@ * and the report says why. Only phrases and titles ever go to Wikipedia; the text goes only to the * model, as it does when the model writes. */ -import { ownerSection } from "../../src/core/links"; +import { ownerSection, targetTitle } from "../../src/core/links"; import { ancestors, descendants, label, notesOf, sections, topOf, tops, type NodeId, type Snap } from "../../src/core/model"; -import type { Ref } from "../../src/core/ref"; import { clip, plain, sentences } from "../../src/core/text"; import type { LinkVerdicts, LLM } from "../../src/llm/types"; import type { WikiClient } from "../wiki"; @@ -118,8 +117,6 @@ const linkedTitles = (snap: Snap, id: NodeId): string[] => return r ? [targetTitle(snap, r)] : []; }); -const targetTitle = (snap: Snap, r: Ref) => (r.kind === "wiki" ? r.title : r.kind === "url" ? (r.title ?? r.url) : r.id && snap.nodes[r.id] ? label(snap, r.id) : (r.path ?? []).join(" › ") || "a note"); - /** Everything already linked under a top, in reading order, each title once. */ function linkedInTop(snap: Snap, top: NodeId): string[] { const out = new Set(); diff --git a/src/core/links.ts b/src/core/links.ts index 7210056..607b3b7 100644 --- a/src/core/links.ts +++ b/src/core/links.ts @@ -5,12 +5,18 @@ * A link is a note with a target and no body, so it is anchored, orphaned, healed, merged, undone * and versioned like any note. Nothing here is stored except through ops; the index is derived. */ -import { Doc, ancestors, notesOf, sections, topOf, type Actor, type NodeId, type NodeSnap, type Op, type Snap } from "./model"; +import { Doc, ancestors, label, notesOf, sections, topOf, type Actor, type NodeId, type NodeSnap, type Op, type Snap } from "./model"; import { sameTarget, wikiKey, type Ref } from "./ref"; import { clip, type Range } from "./text"; // ---- finding a node target ---- +/** A target's title, as the links list and the reviewer name it: a node's (its titles down to it when it is gone), an article's or a page's. */ +export function targetTitle(snap: Snap, r: Ref): string { + if (r.kind === "node") return r.id && snap.nodes[r.id] ? label(snap, r.id) : (r.path ?? []).join(" › ") || "a note"; + return r.kind === "wiki" ? r.title : (r.title ?? r.url); +} + /** The nearest section at or above a node: the place a note's text is read in. */ export function ownerSection(snap: Snap, id: NodeId): NodeId { let n = snap.nodes[id]; diff --git a/src/ui/linker.ts b/src/ui/linker.ts index 5df3707..dde4721 100644 --- a/src/ui/linker.ts +++ b/src/ui/linker.ts @@ -13,9 +13,9 @@ import type { JobState } from "../../server/links/jobs"; import type { ReviewReport } from "../../server/links/review"; import type { Related as RelatedRow, Suggestion as Sugg } from "../../server/links/scan"; import { inArticles } from "../core/article"; -import { applyLinks, nodeRef, phraseKey } from "../core/links"; +import { applyLinks, nodeRef, phraseKey, targetTitle } from "../core/links"; import type { Mark } from "../core/marks"; -import { ancestors, isLibraryRoot, isLink, label, notesOf, topOf, tops, type Doc, type NodeId, type Op, type Snap } from "../core/model"; +import { ancestors, isLibraryRoot, isLink, notesOf, topOf, tops, type Doc, type NodeId, type Op, type Snap } from "../core/model"; import { describeTarget, sameTarget, type Ref } from "../core/ref"; import { libApi } from "./api"; import { clip, overlaps, type Range } from "../core/text"; @@ -109,12 +109,6 @@ function locate(body: string, s: Sugg): Range | null { return at < 0 ? null : [at, at + s.quote.length]; } -/** A target's title, for a row. */ -function titleOf(snap: Snap, r: Ref): string { - if (r.kind === "node") return r.id && snap.nodes[r.id] ? label(snap, r.id) : (r.path ?? []).join(" › ") || "a note"; - return r.kind === "wiki" ? r.title : (r.title ?? r.url); -} - /** A stored suggestion as a row, as things stand in the text now; null if its words are gone or carry another link. */ function rowOf(snap: Snap, s: Sugg): LinkRow | null { const n = snap.nodes[s.node]; @@ -201,7 +195,7 @@ export class Linker { const a = note.anchors[0]; if (!note.ref || !a || mine.some((x) => x.note === c)) continue; const quote = n.body.slice(a.start, a.end); - mine.push({ key: `note:${c}`, node: id, range: [a.start, a.end], quote, target: note.ref, title: titleOf(snap, note.ref), status: "linked", by: null, reason: null, verdict: null, note: c }); + mine.push({ key: `note:${c}`, node: id, range: [a.start, a.end], quote, target: note.ref, title: targetTitle(snap, note.ref), status: "linked", by: null, reason: null, verdict: null, note: c }); seen.add(phraseKey(quote)); } for (const k of n.nolink ?? []) {