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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-17 16:26:32 -05:00
1 parent dbbe3effac
commit e6d71e84de
3 files changed
+11 -14

No files matched your search

+1 -4
View File
@@ -11,9 +11,8 @@
* and the report says why. Only phrases and titles ever go to Wikipedia; the text goes only to the * 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. * 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 { 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 { clip, plain, sentences } from "../../src/core/text";
import type { LinkVerdicts, LLM } from "../../src/llm/types"; import type { LinkVerdicts, LLM } from "../../src/llm/types";
import type { WikiClient } from "../wiki"; import type { WikiClient } from "../wiki";
@@ -118,8 +117,6 @@ const linkedTitles = (snap: Snap, id: NodeId): string[] =>
return r ? [targetTitle(snap, r)] : []; 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. */ /** Everything already linked under a top, in reading order, each title once. */
function linkedInTop(snap: Snap, top: NodeId): string[] { function linkedInTop(snap: Snap, top: NodeId): string[] {
const out = new Set<string>(); const out = new Set<string>();
+7 -1
View File
@@ -5,12 +5,18 @@
* A link is a note with a target and no body, so it is anchored, orphaned, healed, merged, undone * 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. * 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 { sameTarget, wikiKey, type Ref } from "./ref";
import { clip, type Range } from "./text"; import { clip, type Range } from "./text";
// ---- finding a node target ---- // ---- 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. */ /** 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 { export function ownerSection(snap: Snap, id: NodeId): NodeId {
let n = snap.nodes[id]; let n = snap.nodes[id];
+3 -9
View File
@@ -13,9 +13,9 @@ import type { JobState } from "../../server/links/jobs";
import type { ReviewReport } from "../../server/links/review"; import type { ReviewReport } from "../../server/links/review";
import type { Related as RelatedRow, Suggestion as Sugg } from "../../server/links/scan"; import type { Related as RelatedRow, Suggestion as Sugg } from "../../server/links/scan";
import { inArticles } from "../core/article"; 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 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 { describeTarget, sameTarget, type Ref } from "../core/ref";
import { libApi } from "./api"; import { libApi } from "./api";
import { clip, overlaps, type Range } from "../core/text"; 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]; 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. */ /** 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 { function rowOf(snap: Snap, s: Sugg): LinkRow | null {
const n = snap.nodes[s.node]; const n = snap.nodes[s.node];
@@ -201,7 +195,7 @@ export class Linker {
const a = note.anchors[0]; const a = note.anchors[0];
if (!note.ref || !a || mine.some((x) => x.note === c)) continue; if (!note.ref || !a || mine.some((x) => x.note === c)) continue;
const quote = n.body.slice(a.start, a.end); 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)); seen.add(phraseKey(quote));
} }
for (const k of n.nolink ?? []) { for (const k of n.nolink ?? []) {