@descent-vtt/spec-graph 0.13.1 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAiGpF,mEAAmE;AACnE,MAAM,UAAU,aAAa,CAC3B,SAAuC,EACvC,OAAO,GAAmB,EAAE;IAE5B,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,MAAM,WAAW,GAAiB,EAAE,CAAC;IAErC,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7C,QAAQ,CAAC,IAAI,CAAC;gBACZ,OAAO,EAAE,0BAA0B,KAAK,CAAC,QAAQ,CAAC,EAAE,0BAA0B,QAAQ,CAAC,IAAI,EAAE;gBAC7F,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE;aACtB,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QACD,KAAK,CAAC,GAAG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,UAAU,EAAE,EAAE,EAAE,CAAC;AAC1F,CAAC;AAED,SAAS,MAAM,CACb,SAA6B,EAC7B,MAA6B,EAC7B,UAA6B;IAE7B,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,MAAM;QACN,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,GAAG,EAAE,SAAS,CAAC,GAAG;QAClB,UAAU;KACX,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/**\n * Corpus-level reference resolution - the foreign-key check.\n *\n * Extraction produces relations whose targets are still just text. This module\n * turns each into an edge or into an explicit, reportable failure. The whole\n * value of the exercise is in refusing to do either job carelessly:\n *\n * - **A deliberate reference that does not resolve is an error.** A link, a\n * front-matter field or a directive naming a document that does not exist is\n * a broken foreign key, and silence about it is how reference graphs rot.\n * - **An opportunistic reference that does not resolve is nothing.** `ADR-0007`\n * written in prose is a citation; `SHA-256` is not. Since the two are\n * indistinguishable in isolation, bare identifiers are only reported when\n * their family already exists in the corpus - so `ADR-0099` in a repository\n * full of ADRs is a finding, and `T-1000` in the same repository is not.\n * - **Two candidates is worse than none.** A reference that matches several\n * documents is reported as ambiguous rather than silently bound to whichever\n * one happened to be indexed first.\n */\n\nimport type { ExtractedDocument, ReferenceCandidate } from './extract.js';\nimport {\n isDocumentTarget,\n isExternal,\n looksLikePath,\n normaliseRef,\n parseBareRef,\n parsePrefixedRef,\n splitAnchor,\n withinOneEdit,\n} from './identity.js';\nimport { basenamePosix, dirnamePosix, extnamePosix, resolveFrom } from './paths.js';\nimport type {\n DanglingRef,\n DocumentNode,\n Edge,\n ItemNode,\n MisreadKey,\n ParseProblem,\n SpecNode,\n SuppressedRef,\n} from './types.js';\n\nexport interface ResolveOptions {\n /**\n * Whether a repository-relative path exists on disk.\n *\n * Used only to tell \"you linked to a file that is not a specification\" apart\n * from \"you linked to nothing at all\", which are different mistakes with\n * different fixes.\n */\n readonly fileExists?: ((path: string) => boolean) | undefined;\n /**\n * Whether a repository-relative path is a directory on disk.\n *\n * A link to a directory cites no document, written with a trailing slash or\n * without one: `[the guides](../guides)` names a directory as surely as\n * `[the guides](../guides/)` does.\n */\n readonly isDirectory?: ((path: string) => boolean) | undefined;\n /**\n * Targets whose failure to resolve should not be reported.\n *\n * This is a *suppression* filter, not a resolution one: it is consulted only\n * when a reference has already failed to resolve. A reference that resolves\n * still becomes an edge no matter what this says, so no amount of\n * configuration can silently delete a relation from the graph.\n */\n readonly isIgnoredReference?: ((target: string) => boolean) | undefined;\n /**\n * Families that are never citations in this repository.\n *\n * `RFC 2119` is the canonical case: every specification cites it, and a\n * repository that keeps its own `RFC-*` documents will otherwise read that\n * sentence as a dangling reference to a local RFC 2119 it does not have.\n * Consulted only after resolution has failed, like every other filter here.\n */\n readonly isIgnoredFamily?: ((family: string) => boolean) | undefined;\n}\n\nexport interface ResolvedCorpus {\n readonly nodes: ReadonlyMap<string, SpecNode>;\n readonly documents: readonly DocumentNode[];\n readonly items: readonly ItemNode[];\n readonly edges: readonly Edge[];\n readonly dangling: readonly DanglingRef[];\n readonly problems: readonly ParseProblem[];\n readonly misreadKeys: readonly MisreadKey[];\n /**\n * References this repository declared none of its business.\n *\n * Not findings, and never reported as such - they are the audit trail for\n * the two settings that can silence one. See ADR-0008.\n */\n readonly suppressed: readonly SuppressedRef[];\n}\n\n/**\n * Every set in these maps is created holding its first member, so an entry\n * that is there is never empty and a lookup asks only whether it is there.\n */\ninterface Index {\n readonly byId: Map<string, string>;\n readonly byAlias: Map<string, Set<string>>;\n /** The literal path of a file. Unique: no two files share one. */\n readonly byPath: Map<string, string>;\n /**\n * Spellings that address a file without naming it exactly - the extension\n * dropped, a directory standing for its README. Several files can answer to\n * one of those, so this is a set, exactly as `byAlias` is.\n */\n readonly byPathAlias: Map<string, Set<string>>;\n readonly byFamilyNumber: Map<string, Set<string>>;\n readonly families: Set<string>;\n /** Every file by the directory holding it, for a basename that was mistyped. */\n readonly byDirectory: Map<string, { stem: string; id: string }[]>;\n /**\n * Alias keys grouped by length.\n *\n * A one-edit match can only differ in length by one, so this turns the scan\n * behind a suggestion from the whole corpus into three buckets of it.\n */\n readonly aliasesByLength: Map<number, string[]>;\n readonly anchors: Map<string, ReadonlySet<string>>;\n readonly itemIds: Set<string>;\n readonly familyOf: Map<string, string | null>;\n}\n\n/** Resolves every extracted reference against the whole corpus. */\nexport function resolveCorpus(\n extracted: readonly ExtractedDocument[],\n options: ResolveOptions = {},\n): ResolvedCorpus {\n const index = buildIndex(extracted);\n const nodes = new Map<string, SpecNode>();\n const documents: DocumentNode[] = [];\n const items: ItemNode[] = [];\n const problems: ParseProblem[] = [];\n const misreadKeys: MisreadKey[] = [];\n\n for (const entry of extracted) {\n const existing = nodes.get(entry.document.id);\n if (existing && existing.kind === 'document') {\n problems.push({\n message: `duplicate document id \"${entry.document.id}\", already declared by ${existing.path}`,\n at: entry.document.at,\n });\n continue;\n }\n nodes.set(entry.document.id, entry.document);\n documents.push(entry.document);\n for (const item of entry.items) {\n // Nodes are keyed by id, so a second item would replace the first in the\n // graph while both were still counted, and one of them would vanish from\n // the export without a word.\n const taken = nodes.get(item.id);\n if (taken) {\n problems.push({\n message: `duplicate item id \"${item.id}\", already taken at ${taken.at.file}:${taken.at.span.start.line}`,\n at: item.at,\n });\n continue;\n }\n nodes.set(item.id, item);\n items.push(item);\n }\n problems.push(...entry.problems);\n misreadKeys.push(...entry.misreadKeys);\n }\n\n const edges: Edge[] = [];\n const dangling: DanglingRef[] = [];\n const suppressed: SuppressedRef[] = [];\n const byKey = new Map<string, number>();\n\n // Structural edges: a register contains the specifications written inside it.\n // A duplicate id leaves another file's document under that id, so the edge is\n // drawn only from this file's own document to a region of it the graph kept:\n // checked by presence alone, it said an unrelated file held the row. A\n // region's file is extracted before it, so its container's id is taken.\n for (const entry of extracted) {\n if (entry.containerId === null) continue;\n const container = nodes.get(entry.containerId) as SpecNode;\n if (container.at.file !== entry.document.at.file || nodes.get(entry.document.id) !== entry.document) continue;\n edges.push({\n kind: 'contains',\n from: entry.containerId,\n to: entry.document.id,\n origin: 'structural',\n declaredAt: entry.document.at,\n raw: entry.document.title,\n declaredIn: [entry.document.at.file],\n reflexive: false,\n });\n }\n\n // Structural edges: a document contains its items.\n for (const item of items) {\n edges.push({\n kind: 'contains',\n from: item.document,\n to: item.id,\n origin: 'structural',\n declaredAt: item.at,\n raw: item.text,\n declaredIn: [item.at.file],\n reflexive: false,\n });\n }\n\n for (const entry of extracted) {\n for (const candidate of entry.references) {\n if (!nodes.has(candidate.from)) continue;\n const outcome = resolveOne(candidate, entry, index, nodes, options);\n if (outcome === null) continue;\n if ('by' in outcome) {\n suppressed.push(outcome);\n continue;\n }\n if ('reason' in outcome) {\n dangling.push(outcome);\n continue;\n }\n // Collapse duplicates: the same relation stated twice is one edge - but\n // every declaration site is kept, because a supersession recorded in only\n // one of the two documents is itself a finding.\n const key = `${outcome.kind} ${outcome.from} ${outcome.to}`;\n const existing = byKey.get(key);\n if (existing !== undefined) {\n const previous = edges[existing] as Edge;\n if (!previous.declaredIn.includes(outcome.declaredAt.file)) {\n edges[existing] = { ...previous, declaredIn: [...previous.declaredIn, outcome.declaredAt.file] };\n }\n continue;\n }\n byKey.set(key, edges.length);\n edges.push(outcome);\n }\n }\n\n return { nodes, documents, items, edges, dangling, problems, misreadKeys, suppressed };\n}\n\n/* -------------------------------------------------------------------------- */\n/* Indexing */\n/* -------------------------------------------------------------------------- */\n\nfunction buildIndex(extracted: readonly ExtractedDocument[]): Index {\n const index: Index = {\n byId: new Map(),\n byAlias: new Map(),\n byPath: new Map(),\n byPathAlias: new Map(),\n byFamilyNumber: new Map(),\n families: new Set(),\n byDirectory: new Map(),\n aliasesByLength: new Map(),\n anchors: new Map(),\n itemIds: new Set(),\n familyOf: new Map(),\n };\n\n for (const entry of extracted) {\n const id = entry.document.id;\n index.byId.set(normaliseRef(id), id);\n index.anchors.set(id, entry.anchors);\n index.familyOf.set(id, entry.identity.family);\n\n for (const alias of entry.document.aliases) {\n const set = index.byAlias.get(alias) ?? new Set<string>();\n set.add(id);\n index.byAlias.set(alias, set);\n }\n\n // Only a file answers to its path. A region keeps the path on its node, so a\n // finding can say where it lives and `document[path=...]` can select it, but\n // it must not be reachable *by* that path: two nodes answering to one path\n // makes every link to the file ambiguous, and this index resolves a\n // collision by keeping whichever was written last. A link to a file holding\n // a register bound to its final row, quietly and with no diagnostic, and\n // anchors were then checked against that row's span rather than the file's.\n // ADR-0009 said a region does not claim the file's path; this is the index\n // where that had to be true.\n if (entry.containerId === null) {\n const path = entry.document.path.toLowerCase();\n index.byPath.set(path, id);\n for (const spelling of pathAliases(entry.document.path)) {\n const set = index.byPathAlias.get(spelling) ?? new Set<string>();\n set.add(id);\n index.byPathAlias.set(spelling, set);\n }\n const directory = dirnamePosix(path);\n const siblings = index.byDirectory.get(directory) ?? [];\n siblings.push({ stem: stemOf(path), id });\n index.byDirectory.set(directory, siblings);\n }\n\n if (entry.identity.family !== null && entry.identity.number !== null) {\n index.families.add(entry.identity.family);\n const key = `${entry.identity.family}:${entry.identity.number}`;\n const set = index.byFamilyNumber.get(key) ?? new Set<string>();\n set.add(id);\n index.byFamilyNumber.set(key, set);\n }\n\n for (const item of entry.items) index.itemIds.add(item.id);\n }\n\n // A bucket seeded with anything but the empty list would hold a spelling no\n // document answers to, which a suggestion finds no id for and skips.\n for (const alias of index.byAlias.keys()) {\n const bucket = index.aliasesByLength.get(alias.length) ?? [];\n bucket.push(alias);\n index.aliasesByLength.set(alias.length, bucket);\n }\n\n return index;\n}\n\n/** A file name with its extension taken off: `docs/a/0004-sharding.md` -> `0004-sharding`. */\nfunction stemOf(path: string): string {\n const base = basenamePosix(path);\n return base.slice(0, base.length - extnamePosix(base).length);\n}\n\n/**\n * Every spelling of a path that addresses a file without naming it exactly.\n *\n * None of them is ever a file's own whole path, and one that is another file's\n * - the stem of `docs/a.md.md` is `docs/a.md` - cannot make a link to that file\n * ambiguous, because `lookupExact` asks for the literal path first.\n */\nfunction pathAliases(path: string): string[] {\n const keys = new Set<string>();\n const extension = extnamePosix(path);\n // Without an extension the stem is the path itself, which the literal path\n // already answers to first: adding it anyway changes no lookup.\n if (extension.length > 0) keys.add(path.slice(0, path.length - extension.length).toLowerCase());\n // `docs/adr/0007/README.md` is also addressed as `docs/adr/0007`.\n const base = basenamePosix(path);\n if (/^(readme|index)\\./i.test(base)) {\n // A repository-relative path never starts with `/`, so this is never\n // empty and the check decides nothing. At the root it is the name cut\n // short, `readme.m`: `.m` is not a document's extension, so only a link\n // that percent-escaped that dot would ever be looked up by it.\n const parent = path.slice(0, path.length - base.length - 1);\n if (parent.length > 0) keys.add(parent.toLowerCase());\n }\n return [...keys];\n}\n\n/* -------------------------------------------------------------------------- */\n/* Resolution */\n/* -------------------------------------------------------------------------- */\n\nfunction resolveOne(\n candidate: ReferenceCandidate,\n entry: ExtractedDocument,\n index: Index,\n nodes: ReadonlyMap<string, SpecNode>,\n options: ResolveOptions,\n): Edge | DanglingRef | SuppressedRef | null {\n const { target: bare, anchor } = splitAnchor(candidate.target);\n\n // A pure `#anchor` points inside the citing document. Extraction never hands\n // over an empty target, so an empty part before the `#` always has an anchor\n // after it: the second test is for the type.\n if (bare.length === 0 && anchor !== null) {\n return bindAnchor(candidate, entry.document.id, anchor, index, nodes, options);\n }\n\n if (isExternal(bare)) return null;\n // A link to source code, an image or a config file is not a specification\n // reference. Validating it would report an error on the most ordinary thing a\n // design document does.\n if (!isDocumentTarget(bare)) return null;\n\n const found = lookup(bare, entry, index);\n\n if (found.ids.length === 0) {\n if (candidate.opportunistic && !worthReporting(bare, index)) return null;\n const silenced = filteredBy(candidate.target, bare, options);\n if (silenced !== null) return suppression(candidate, silenced);\n // A trailing slash names a directory. Linking to one is ordinary - \"the\n // decisions live in [archive/](archive/)\" - and is not a citation of any\n // document. Resolution is still attempted first, so a directory-style\n // document written as `0007-sharding/` continues to resolve. Without the\n // slash, the disk says whether the path is a directory.\n if (bare.endsWith('/') || isDirectoryPath(bare, entry, options)) return null;\n const reason = pathMissingReason(bare, entry, options);\n return dangle(candidate, reason, found.near);\n }\n\n if (found.ids.length > 1) {\n if (candidate.opportunistic) return null;\n const silenced = filteredBy(candidate.target, bare, options);\n if (silenced !== null) return suppression(candidate, silenced);\n return dangle(candidate, 'ambiguous', found.ids);\n }\n\n const documentId = found.ids[0] as string;\n\n // A document naming itself in prose - almost always its own H1, `# ADR-0007:\n // Sharding` - is not a citation. Deliberate self-links are kept, because a\n // link that points at its own document is a real mistake worth reporting.\n if (candidate.opportunistic && documentId === entry.document.id) return null;\n\n if (anchor !== null) return bindAnchor(candidate, documentId, anchor, index, nodes, options);\n\n return makeEdge(candidate, documentId);\n}\n\ninterface Lookup {\n readonly ids: readonly string[];\n /** Near-misses worth suggesting in the report. */\n readonly near: readonly string[];\n}\n\n/**\n * The same path with its percent-escapes read.\n *\n * `[Design](docs/my%20design.md)` is what a renderer, a documentation site and\n * GitHub's own \"copy link\" all produce for a file with a space in its name, and\n * it names a real file. Returns `null` when there was nothing to decode or when\n * the escapes are malformed - `100%` in a path is not an escape sequence, and\n * `decodeURIComponent` throws on it.\n */\nfunction percentDecoded(target: string): string | null {\n // Either test stands in for the other: with no `%` the decode gives the text\n // back unchanged, and with one a decode that succeeds always changes it.\n if (!target.includes('%')) return null;\n try {\n const decoded = decodeURIComponent(target);\n return decoded === target ? null : decoded;\n } catch {\n return null;\n }\n}\n\n/** `near` is read only when nothing resolved, so what the early returns put there is never read. */\nfunction lookup(target: string, entry: ExtractedDocument, index: Index): Lookup {\n const exact = lookupExact(target, entry, index);\n if (exact.length > 0) return { ids: exact, near: [] };\n // Tried second and never first, so a repository holding a file whose name\n // genuinely contains a percent escape keeps resolving by its written spelling.\n const decoded = percentDecoded(target);\n const relaxed = decoded === null ? [] : lookupExact(decoded, entry, index);\n if (relaxed.length > 0) return { ids: relaxed, near: [] };\n // Suggestions are computed only once resolution has failed outright, so their\n // cost is bounded by the number of findings rather than by the corpus.\n return { ids: [], near: nearMisses(target, entry, index) };\n}\n\nfunction lookupExact(target: string, entry: ExtractedDocument, index: Index): readonly string[] {\n if (looksLikePath(target)) {\n const resolved = resolveFrom(entry.document.path, target).toLowerCase();\n // Naming the file exactly is never ambiguous, whatever else is spelled the\n // same way.\n const byPath = index.byPath.get(resolved);\n if (byPath) return [byPath];\n // An inexact spelling can belong to more than one file: `docs/A` is both\n // `docs/A.md` with its extension dropped and `docs/A/README.md` standing\n // for its directory. Handing back every claimant makes that an\n // ambiguous-reference the author can settle, rather than a silent pick of\n // whichever happened to be indexed last.\n const spelled = index.byPathAlias.get(resolved);\n if (spelled) return [...spelled];\n // A path may still be spelled as an identifier in a nested folder layout.\n const stem = basenamePosix(resolved);\n const byStem = index.byAlias.get(normaliseRef(stem.replace(/\\.[^.]+$/, '')));\n if (byStem) return [...byStem];\n return [];\n }\n\n const key = normaliseRef(target);\n if (key.length === 0) return [];\n\n const byId = index.byId.get(key);\n if (byId) return [byId];\n\n const byAlias = index.byAlias.get(key);\n if (byAlias) return [...byAlias];\n\n const prefixed = parsePrefixedRef(target);\n if (prefixed) {\n const byFamily = index.byFamilyNumber.get(`${prefixed.family}:${prefixed.number}`);\n if (byFamily) return [...byFamily];\n return [];\n }\n\n // A bare number resolves only inside the citing document's own family. A\n // repository with both `adr/0007` and `rfc/0007` is ordinary, and guessing\n // between them would be worse than reporting nothing.\n // Without a number, or without a family, the key names no entry either, so\n // the two tests that return early save a lookup and decide nothing alone.\n const number = parseBareRef(target);\n if (number !== null) {\n const family = index.familyOf.get(entry.document.id) ?? null;\n if (family === null) return [];\n const byFamily = index.byFamilyNumber.get(`${family}:${number}`);\n if (byFamily) return [...byFamily];\n }\n\n return [];\n}\n\n/* -------------------------------------------------------------------------- */\n/* Near misses */\n/* -------------------------------------------------------------------------- */\n\n/**\n * The one document a failed reference was probably meant to name.\n *\n * A suggestion is cheap to read and expensive to get wrong: \"did you mean\n * ADR-0008?\" against a citation that meant ADR-0012 sends a reader to the wrong\n * decision with a confidence nobody earned. So the bar is not closeness, it is\n * closeness *in the part of the spelling that is not the identity*. A family\n * name is a word people misremember. A number is the identity itself, and\n * `ADR-0009` sits one edit from every neighbour it has - so numbers are never\n * guessed at, and a repository of fifteen ADRs citing a sixteenth is told the\n * plain truth instead.\n *\n * Two gates, plus a fallback:\n *\n * - a path in the right directory whose basename is one edit out - a typo;\n * - a family one edit out with its number intact - `ARD-0009` for `ADR-0009`.\n *\n * Anything else falls through to a one-edit match against the folded spellings\n * documents already answer to, which is where a mistyped slug or wiki name\n * lands.\n *\n * There is deliberately no gate for a file that moved. Resolution already binds\n * a path by its basename, so `../guides/onboarding.md` finds the document that\n * is now in `handbook/` without anybody being asked to confirm a guess - and a\n * suggestion nobody needs is a suggestion that can only be wrong.\n *\n * Every gate ends the same way: **exactly one** candidate, or nothing. Two\n * suggestions is the ambiguity this module refuses to resolve anywhere else,\n * and the tail of a hint is no place to start.\n */\nfunction nearMisses(target: string, entry: ExtractedDocument, index: Index): string[] {\n if (looksLikePath(target)) {\n const resolved = resolveFrom(entry.document.path, target).toLowerCase();\n const stem = stemOf(resolved);\n const siblings = index.byDirectory.get(dirnamePosix(resolved)) ?? [];\n return sole(siblings.filter((file) => withinOneEdit(file.stem, stem)).map((file) => file.id));\n }\n\n const prefixed = parsePrefixedRef(target);\n if (prefixed !== null) {\n const hits: string[] = [];\n for (const family of index.families) {\n // The family as written needs no exclusion: one edit is never zero edits.\n if (!withinOneEdit(family.toLowerCase(), prefixed.family.toLowerCase())) continue;\n for (const id of index.byFamilyNumber.get(`${family}:${prefixed.number}`) ?? []) hits.push(id);\n }\n return sole(hits);\n }\n\n // A bare `12` carries nothing but a number, which is the one thing this\n // refuses to guess at.\n if (parseBareRef(target) !== null) return [];\n\n const key = normaliseRef(target);\n if (key.length < MIN_SUGGESTIBLE) return [];\n const hits: string[] = [];\n // Every bucketed spelling is a key of `byAlias`, so its `?? []` is for the\n // type; and a spelling in place of an empty bucket names no document here.\n for (const length of [key.length - 1, key.length, key.length + 1]) {\n for (const alias of index.aliasesByLength.get(length) ?? []) {\n if (!withinOneEdit(alias, key)) continue;\n for (const id of index.byAlias.get(alias) ?? []) hits.push(id);\n }\n }\n return sole(hits);\n}\n\n/**\n * How long a folded spelling has to be before one edit means anything.\n *\n * Below six characters an edit is most of the word, and every corpus is full of\n * short names that differ by exactly that much.\n */\nconst MIN_SUGGESTIBLE = 6;\n\n/** The candidates, if there is exactly one of them. Otherwise nothing. */\nfunction sole(ids: Iterable<string>): string[] {\n const unique = new Set(ids);\n return unique.size === 1 ? [...unique] : [];\n}\n\n/**\n * Which setting, if any, declared this reference none of the repository's\n * business.\n *\n * Returns the mechanism rather than a boolean so the audit trail can say which\n * line of configuration to go and look at. A team that silenced eight things\n * with one glob and one with a family needs to be told them apart.\n */\nfunction filteredBy(target: string, bare: string, options: ResolveOptions): SuppressedRef['by'] | null {\n if (options.isIgnoredReference?.(target)) return 'reference';\n const prefixed = parsePrefixedRef(bare);\n if (prefixed !== null && options.isIgnoredFamily?.(prefixed.family) === true) return 'family';\n return null;\n}\n\n/**\n * Whether an unresolved bare identifier deserves a report.\n *\n * Only when the corpus already contains that family. `ADR-0099` in a repository\n * of ADRs is a real dangling citation; `T-1000` in the same repository is a\n * sentence about a robot.\n */\nfunction worthReporting(target: string, index: Index): boolean {\n const prefixed = parsePrefixedRef(target);\n return prefixed !== null && index.families.has(prefixed.family);\n}\n\n/** True when a path-like target names a directory, as `../guides` can. */\nfunction isDirectoryPath(target: string, entry: ExtractedDocument, options: ResolveOptions): boolean {\n if (!looksLikePath(target) || !options.isDirectory) return false;\n return options.isDirectory(resolveFrom(entry.document.path, target));\n}\n\nfunction pathMissingReason(\n target: string,\n entry: ExtractedDocument,\n options: ResolveOptions,\n): DanglingRef['reason'] {\n if (!looksLikePath(target) || !options.fileExists) return 'unknown-target';\n const resolved = resolveFrom(entry.document.path, target);\n return options.fileExists(resolved) ? 'not-a-spec' : 'unknown-target';\n}\n\n/**\n * Binds a `#anchor` to an item or a section.\n *\n * Anchors are how a delegation names a specific obligation rather than a whole\n * document, so resolving them precisely is what lets a ghost-handover finding\n * say *which* question was handed into the archive.\n */\nfunction bindAnchor(\n candidate: ReferenceCandidate,\n documentId: string,\n anchor: string,\n index: Index,\n nodes: ReadonlyMap<string, SpecNode>,\n options: ResolveOptions,\n): Edge | DanglingRef | SuppressedRef | null {\n const itemId = `${documentId}#${anchor}`;\n if (index.itemIds.has(itemId)) return makeEdge(candidate, itemId);\n\n // Every document, a file or a region of one, registered its anchors, and a\n // document id here is always one of theirs.\n const anchors = index.anchors.get(documentId) as ReadonlySet<string>;\n if (anchors.has(anchor.toLowerCase())) return makeEdge(candidate, documentId);\n\n // Some renderers slugify differently; try the loosest reasonable match before\n // calling it broken.\n const loose = anchor.toLowerCase().replace(/[^\\p{L}\\p{N}]+/gu, '-').replace(/^-|-$/g, '');\n if (anchors.has(loose)) return makeEdge(candidate, documentId);\n\n const silenced = filteredBy(candidate.target, splitAnchor(candidate.target).target, options);\n if (silenced !== null) return suppression(candidate, silenced);\n\n const candidates = [...(nodes.keys() as Iterable<string>)].filter(\n (id) => id.startsWith(`${documentId}#`) && id.toLowerCase().includes(loose),\n );\n return {\n kind: candidate.kind,\n from: candidate.from,\n target: candidate.target,\n reason: 'unknown-anchor',\n origin: candidate.origin,\n declaredAt: candidate.declaredAt,\n raw: candidate.raw,\n candidates,\n };\n}\n\nfunction makeEdge(candidate: ReferenceCandidate, resolved: string): Edge {\n const from = candidate.inverted ? resolved : candidate.from;\n const to = candidate.inverted ? candidate.from : resolved;\n return {\n kind: candidate.kind,\n from,\n to,\n origin: candidate.origin,\n declaredAt: candidate.declaredAt,\n raw: candidate.raw,\n declaredIn: [candidate.declaredAt.file],\n reflexive: documentOf(from) === documentOf(to),\n };\n}\n\nfunction suppression(candidate: ReferenceCandidate, by: SuppressedRef['by']): SuppressedRef {\n return { target: candidate.target, from: candidate.from, at: candidate.declaredAt, by };\n}\n\nfunction dangle(\n candidate: ReferenceCandidate,\n reason: DanglingRef['reason'],\n candidates: readonly string[],\n): DanglingRef {\n return {\n kind: candidate.kind,\n from: candidate.from,\n target: candidate.target,\n reason,\n origin: candidate.origin,\n declaredAt: candidate.declaredAt,\n raw: candidate.raw,\n candidates,\n };\n}\n\n/** The document part of a node id: `ADR-7#q.1` -> `ADR-7`. */\nexport function documentOf(nodeId: string): string {\n const hash = nodeId.indexOf('#');\n return hash === -1 ? nodeId : nodeId.slice(0, hash);\n}\n"]}
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA0GpF,mEAAmE;AACnE,MAAM,UAAU,aAAa,CAC3B,SAAuC,EACvC,OAAO,GAAmB,EAAE;IAE5B,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,MAA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n *\n * Extraction produces relations whose targets are still just text. This module\n * turns each into an edge or into an explicit, reportable failure. The whole\n * value of the exercise is in refusing to do either job carelessly:\n *\n * - **A deliberate reference that does not resolve is an error.** A link, a\n * front-matter field or a directive naming a document that does not exist is\n * a broken foreign key, and silence about it is how reference graphs rot.\n * - **An opportunistic reference that does not resolve is nothing.** `ADR-0007`\n * written in prose is a citation; `SHA-256` is not. Since the two are\n * indistinguishable in isolation, bare identifiers are only reported when\n * their family already exists in the corpus - so `ADR-0099` in a repository\n * full of ADRs is a finding, and `T-1000` in the same repository is not.\n * - **Two candidates is worse than none.** A reference that matches several\n * documents is reported as ambiguous rather than silently bound to whichever\n * one happened to be indexed first.\n */\n\nimport type { ExtractedDocument, ReferenceCandidate } from './extract.js';\nimport {\n isDocumentTarget,\n isExternal,\n looksLikePath,\n normaliseRef,\n parseBareRef,\n parsePrefixedRef,\n splitAnchor,\n withinOneEdit,\n} from './identity.js';\nimport { basenamePosix, dirnamePosix, extnamePosix, resolveFrom } from './paths.js';\nimport type {\n DanglingRef,\n DocumentNode,\n Edge,\n ItemNode,\n MisreadKey,\n ParseProblem,\n SpecNode,\n SuppressedRef,\n} from './types.js';\n\nexport interface ResolveOptions {\n /**\n * Whether a repository-relative path exists on disk.\n *\n * Used only to tell \"you linked to a file that is not a specification\" apart\n * from \"you linked to nothing at all\", which are different mistakes with\n * different fixes.\n */\n readonly fileExists?: ((path: string) => boolean) | undefined;\n /**\n * Whether a repository-relative path is a directory on disk.\n *\n * A link to a directory cites no document, written with a trailing slash or\n * without one: `[the guides](../guides)` names a directory as surely as\n * `[the guides](../guides/)` does.\n */\n readonly isDirectory?: ((path: string) => boolean) | undefined;\n /**\n * Targets whose failure to resolve should not be reported.\n *\n * This is a *suppression* filter, not a resolution one: it is consulted only\n * when a reference has already failed to resolve. A reference that resolves\n * still becomes an edge no matter what this says, so no amount of\n * configuration can silently delete a relation from the graph.\n */\n readonly isIgnoredReference?: ((target: string) => boolean) | undefined;\n /**\n * Families that are never citations in this repository.\n *\n * `RFC 2119` is the canonical case: every specification cites it, and a\n * repository that keeps its own `RFC-*` documents will otherwise read that\n * sentence as a dangling reference to a local RFC 2119 it does not have.\n * Consulted only after resolution has failed, like every other filter here.\n */\n readonly isIgnoredFamily?: ((family: string) => boolean) | undefined;\n}\n\nexport interface ResolvedCorpus {\n readonly nodes: ReadonlyMap<string, SpecNode>;\n readonly documents: readonly DocumentNode[];\n readonly items: readonly ItemNode[];\n readonly edges: readonly Edge[];\n readonly dangling: readonly DanglingRef[];\n readonly problems: readonly ParseProblem[];\n readonly misreadKeys: readonly MisreadKey[];\n /**\n * References this repository declared none of its business.\n *\n * Not findings, and never reported as such - they are the audit trail for\n * the two settings that can silence one. See ADR-0008.\n */\n readonly suppressed: readonly SuppressedRef[];\n /**\n * The families a document here belongs to, sorted: those an identifier of\n * some document names, as `ADR` is named by `ADR-0007`.\n *\n * What a citation in prose is witnessed by (ADR-0004), and what an\n * allowlist of families is held against: one that names none of these\n * allows nothing the corpus has (ADR-0010).\n */\n readonly families: readonly string[];\n}\n\n/**\n * Every set in these maps is created holding its first member, so an entry\n * that is there is never empty and a lookup asks only whether it is there.\n */\ninterface Index {\n readonly byId: Map<string, string>;\n readonly byAlias: Map<string, Set<string>>;\n /** The literal path of a file. Unique: no two files share one. */\n readonly byPath: Map<string, string>;\n /**\n * Spellings that address a file without naming it exactly - the extension\n * dropped, a directory standing for its README. Several files can answer to\n * one of those, so this is a set, exactly as `byAlias` is.\n */\n readonly byPathAlias: Map<string, Set<string>>;\n readonly byFamilyNumber: Map<string, Set<string>>;\n readonly families: Set<string>;\n /** Every file by the directory holding it, for a basename that was mistyped. */\n readonly byDirectory: Map<string, { stem: string; id: string }[]>;\n /**\n * Alias keys grouped by length.\n *\n * A one-edit match can only differ in length by one, so this turns the scan\n * behind a suggestion from the whole corpus into three buckets of it.\n */\n readonly aliasesByLength: Map<number, string[]>;\n readonly anchors: Map<string, ReadonlySet<string>>;\n readonly itemIds: Set<string>;\n readonly familyOf: Map<string, string | null>;\n}\n\n/** Resolves every extracted reference against the whole corpus. */\nexport function resolveCorpus(\n extracted: readonly ExtractedDocument[],\n options: ResolveOptions = {},\n): ResolvedCorpus {\n const index = buildIndex(extracted);\n const nodes = new Map<string, SpecNode>();\n const documents: DocumentNode[] = [];\n const items: ItemNode[] = [];\n const problems: ParseProblem[] = [];\n const misreadKeys: MisreadKey[] = [];\n\n for (const entry of extracted) {\n const existing = nodes.get(entry.document.id);\n if (existing && existing.kind === 'document') {\n problems.push({\n message: `duplicate document id \"${entry.document.id}\", already declared by ${existing.path}`,\n at: entry.document.at,\n });\n continue;\n }\n nodes.set(entry.document.id, entry.document);\n documents.push(entry.document);\n for (const item of entry.items) {\n // Nodes are keyed by id, so a second item would replace the first in the\n // graph while both were still counted, and one of them would vanish from\n // the export without a word.\n const taken = nodes.get(item.id);\n if (taken) {\n problems.push({\n message: `duplicate item id \"${item.id}\", already taken at ${taken.at.file}:${taken.at.span.start.line}`,\n at: item.at,\n });\n continue;\n }\n nodes.set(item.id, item);\n items.push(item);\n }\n problems.push(...entry.problems);\n misreadKeys.push(...entry.misreadKeys);\n }\n\n const edges: Edge[] = [];\n const dangling: DanglingRef[] = [];\n const suppressed: SuppressedRef[] = [];\n const byKey = new Map<string, number>();\n\n // Structural edges: a register contains the specifications written inside it.\n // A duplicate id leaves another file's document under that id, so the edge is\n // drawn only from this file's own document to a region of it the graph kept:\n // checked by presence alone, it said an unrelated file held the row. A\n // region's file is extracted before it, so its container's id is taken.\n for (const entry of extracted) {\n if (entry.containerId === null) continue;\n const container = nodes.get(entry.containerId) as SpecNode;\n if (container.at.file !== entry.document.at.file || nodes.get(entry.document.id) !== entry.document) continue;\n edges.push({\n kind: 'contains',\n from: entry.containerId,\n to: entry.document.id,\n origin: 'structural',\n declaredAt: entry.document.at,\n raw: entry.document.title,\n declaredIn: [entry.document.at.file],\n reflexive: false,\n });\n }\n\n // Structural edges: a document contains its items.\n for (const item of items) {\n edges.push({\n kind: 'contains',\n from: item.document,\n to: item.id,\n origin: 'structural',\n declaredAt: item.at,\n raw: item.text,\n declaredIn: [item.at.file],\n reflexive: false,\n });\n }\n\n for (const entry of extracted) {\n for (const candidate of entry.references) {\n if (!nodes.has(candidate.from)) continue;\n const outcome = resolveOne(candidate, entry, index, nodes, options);\n if (outcome === null) continue;\n if ('by' in outcome) {\n suppressed.push(outcome);\n continue;\n }\n if ('reason' in outcome) {\n dangling.push(outcome);\n continue;\n }\n // Collapse duplicates: the same relation stated twice is one edge - but\n // every declaration site is kept, because a supersession recorded in only\n // one of the two documents is itself a finding.\n const key = `${outcome.kind} ${outcome.from} ${outcome.to}`;\n const existing = byKey.get(key);\n if (existing !== undefined) {\n const previous = edges[existing] as Edge;\n if (!previous.declaredIn.includes(outcome.declaredAt.file)) {\n edges[existing] = { ...previous, declaredIn: [...previous.declaredIn, outcome.declaredAt.file] };\n }\n continue;\n }\n byKey.set(key, edges.length);\n edges.push(outcome);\n }\n }\n\n return { nodes, documents, items, edges, dangling, problems, misreadKeys, suppressed, families: [...index.families].sort() };\n}\n\n/* -------------------------------------------------------------------------- */\n/* Indexing */\n/* -------------------------------------------------------------------------- */\n\nfunction buildIndex(extracted: readonly ExtractedDocument[]): Index {\n const index: Index = {\n byId: new Map(),\n byAlias: new Map(),\n byPath: new Map(),\n byPathAlias: new Map(),\n byFamilyNumber: new Map(),\n families: new Set(),\n byDirectory: new Map(),\n aliasesByLength: new Map(),\n anchors: new Map(),\n itemIds: new Set(),\n familyOf: new Map(),\n };\n\n for (const entry of extracted) {\n const id = entry.document.id;\n index.byId.set(normaliseRef(id), id);\n index.anchors.set(id, entry.anchors);\n index.familyOf.set(id, entry.identity.family);\n\n for (const alias of entry.document.aliases) {\n const set = index.byAlias.get(alias) ?? new Set<string>();\n set.add(id);\n index.byAlias.set(alias, set);\n }\n\n // Only a file answers to its path. A region keeps the path on its node, so a\n // finding can say where it lives and `document[path=...]` can select it, but\n // it must not be reachable *by* that path: two nodes answering to one path\n // makes every link to the file ambiguous, and this index resolves a\n // collision by keeping whichever was written last. A link to a file holding\n // a register bound to its final row, quietly and with no diagnostic, and\n // anchors were then checked against that row's span rather than the file's.\n // ADR-0009 said a region does not claim the file's path; this is the index\n // where that had to be true.\n if (entry.containerId === null) {\n const path = entry.document.path.toLowerCase();\n index.byPath.set(path, id);\n for (const spelling of pathAliases(entry.document.path)) {\n const set = index.byPathAlias.get(spelling) ?? new Set<string>();\n set.add(id);\n index.byPathAlias.set(spelling, set);\n }\n const directory = dirnamePosix(path);\n const siblings = index.byDirectory.get(directory) ?? [];\n siblings.push({ stem: stemOf(path), id });\n index.byDirectory.set(directory, siblings);\n }\n\n if (entry.identity.family !== null && entry.identity.number !== null) {\n index.families.add(entry.identity.family);\n const key = `${entry.identity.family}:${entry.identity.number}`;\n const set = index.byFamilyNumber.get(key) ?? new Set<string>();\n set.add(id);\n index.byFamilyNumber.set(key, set);\n }\n\n for (const item of entry.items) index.itemIds.add(item.id);\n }\n\n // A bucket seeded with anything but the empty list would hold a spelling no\n // document answers to, which a suggestion finds no id for and skips.\n for (const alias of index.byAlias.keys()) {\n const bucket = index.aliasesByLength.get(alias.length) ?? [];\n bucket.push(alias);\n index.aliasesByLength.set(alias.length, bucket);\n }\n\n return index;\n}\n\n/** A file name with its extension taken off: `docs/a/0004-sharding.md` -> `0004-sharding`. */\nfunction stemOf(path: string): string {\n const base = basenamePosix(path);\n return base.slice(0, base.length - extnamePosix(base).length);\n}\n\n/**\n * Every spelling of a path that addresses a file without naming it exactly.\n *\n * None of them is ever a file's own whole path, and one that is another file's\n * - the stem of `docs/a.md.md` is `docs/a.md` - cannot make a link to that file\n * ambiguous, because `lookupExact` asks for the literal path first.\n */\nfunction pathAliases(path: string): string[] {\n const keys = new Set<string>();\n const extension = extnamePosix(path);\n // Without an extension the stem is the path itself, which the literal path\n // already answers to first: adding it anyway changes no lookup.\n if (extension.length > 0) keys.add(path.slice(0, path.length - extension.length).toLowerCase());\n // `docs/adr/0007/README.md` is also addressed as `docs/adr/0007`.\n const base = basenamePosix(path);\n if (/^(readme|index)\\./i.test(base)) {\n // A repository-relative path never starts with `/`, so this is never\n // empty and the check decides nothing. At the root it is the name cut\n // short, `readme.m`: `.m` is not a document's extension, so only a link\n // that percent-escaped that dot would ever be looked up by it.\n const parent = path.slice(0, path.length - base.length - 1);\n if (parent.length > 0) keys.add(parent.toLowerCase());\n }\n return [...keys];\n}\n\n/* -------------------------------------------------------------------------- */\n/* Resolution */\n/* -------------------------------------------------------------------------- */\n\nfunction resolveOne(\n candidate: ReferenceCandidate,\n entry: ExtractedDocument,\n index: Index,\n nodes: ReadonlyMap<string, SpecNode>,\n options: ResolveOptions,\n): Edge | DanglingRef | SuppressedRef | null {\n const { target: bare, anchor } = splitAnchor(candidate.target);\n\n // A pure `#anchor` points inside the citing document. Extraction never hands\n // over an empty target, so an empty part before the `#` always has an anchor\n // after it: the second test is for the type.\n if (bare.length === 0 && anchor !== null) {\n return bindAnchor(candidate, entry.document.id, anchor, index, nodes, options);\n }\n\n if (isExternal(bare)) return null;\n // A link to source code, an image or a config file is not a specification\n // reference. Validating it would report an error on the most ordinary thing a\n // design document does.\n if (!isDocumentTarget(bare)) return null;\n\n const found = lookup(bare, entry, index);\n\n if (found.ids.length === 0) {\n if (candidate.opportunistic && !worthReporting(bare, index)) return null;\n const silenced = filteredBy(candidate.target, bare, options);\n if (silenced !== null) return suppression(candidate, silenced);\n // A trailing slash names a directory. Linking to one is ordinary - \"the\n // decisions live in [archive/](archive/)\" - and is not a citation of any\n // document. Resolution is still attempted first, so a directory-style\n // document written as `0007-sharding/` continues to resolve. Without the\n // slash, the disk says whether the path is a directory.\n if (bare.endsWith('/') || isDirectoryPath(bare, entry, options)) return null;\n const reason = pathMissingReason(bare, entry, options);\n return dangle(candidate, reason, found.near);\n }\n\n if (found.ids.length > 1) {\n if (candidate.opportunistic) return null;\n const silenced = filteredBy(candidate.target, bare, options);\n if (silenced !== null) return suppression(candidate, silenced);\n return dangle(candidate, 'ambiguous', found.ids);\n }\n\n const documentId = found.ids[0] as string;\n\n // A document naming itself in prose - almost always its own H1, `# ADR-0007:\n // Sharding` - is not a citation. Deliberate self-links are kept, because a\n // link that points at its own document is a real mistake worth reporting.\n if (candidate.opportunistic && documentId === entry.document.id) return null;\n\n if (anchor !== null) return bindAnchor(candidate, documentId, anchor, index, nodes, options);\n\n return makeEdge(candidate, documentId);\n}\n\ninterface Lookup {\n readonly ids: readonly string[];\n /** Near-misses worth suggesting in the report. */\n readonly near: readonly string[];\n}\n\n/**\n * The same path with its percent-escapes read.\n *\n * `[Design](docs/my%20design.md)` is what a renderer, a documentation site and\n * GitHub's own \"copy link\" all produce for a file with a space in its name, and\n * it names a real file. Returns `null` when there was nothing to decode or when\n * the escapes are malformed - `100%` in a path is not an escape sequence, and\n * `decodeURIComponent` throws on it.\n */\nfunction percentDecoded(target: string): string | null {\n // Either test stands in for the other: with no `%` the decode gives the text\n // back unchanged, and with one a decode that succeeds always changes it.\n if (!target.includes('%')) return null;\n try {\n const decoded = decodeURIComponent(target);\n return decoded === target ? null : decoded;\n } catch {\n return null;\n }\n}\n\n/** `near` is read only when nothing resolved, so what the early returns put there is never read. */\nfunction lookup(target: string, entry: ExtractedDocument, index: Index): Lookup {\n const exact = lookupExact(target, entry, index);\n if (exact.length > 0) return { ids: exact, near: [] };\n // Tried second and never first, so a repository holding a file whose name\n // genuinely contains a percent escape keeps resolving by its written spelling.\n const decoded = percentDecoded(target);\n const relaxed = decoded === null ? [] : lookupExact(decoded, entry, index);\n if (relaxed.length > 0) return { ids: relaxed, near: [] };\n // Suggestions are computed only once resolution has failed outright, so their\n // cost is bounded by the number of findings rather than by the corpus.\n return { ids: [], near: nearMisses(target, entry, index) };\n}\n\nfunction lookupExact(target: string, entry: ExtractedDocument, index: Index): readonly string[] {\n if (looksLikePath(target)) {\n const resolved = resolveFrom(entry.document.path, target).toLowerCase();\n // Naming the file exactly is never ambiguous, whatever else is spelled the\n // same way.\n const byPath = index.byPath.get(resolved);\n if (byPath) return [byPath];\n // An inexact spelling can belong to more than one file: `docs/A` is both\n // `docs/A.md` with its extension dropped and `docs/A/README.md` standing\n // for its directory. Handing back every claimant makes that an\n // ambiguous-reference the author can settle, rather than a silent pick of\n // whichever happened to be indexed last.\n const spelled = index.byPathAlias.get(resolved);\n if (spelled) return [...spelled];\n // A path may still be spelled as an identifier in a nested folder layout.\n const stem = basenamePosix(resolved);\n const byStem = index.byAlias.get(normaliseRef(stem.replace(/\\.[^.]+$/, '')));\n if (byStem) return [...byStem];\n return [];\n }\n\n const key = normaliseRef(target);\n if (key.length === 0) return [];\n\n const byId = index.byId.get(key);\n if (byId) return [byId];\n\n const byAlias = index.byAlias.get(key);\n if (byAlias) return [...byAlias];\n\n const prefixed = parsePrefixedRef(target);\n if (prefixed) {\n const byFamily = index.byFamilyNumber.get(`${prefixed.family}:${prefixed.number}`);\n if (byFamily) return [...byFamily];\n return [];\n }\n\n // A bare number resolves only inside the citing document's own family. A\n // repository with both `adr/0007` and `rfc/0007` is ordinary, and guessing\n // between them would be worse than reporting nothing.\n // Without a number, or without a family, the key names no entry either, so\n // the two tests that return early save a lookup and decide nothing alone.\n const number = parseBareRef(target);\n if (number !== null) {\n const family = index.familyOf.get(entry.document.id) ?? null;\n if (family === null) return [];\n const byFamily = index.byFamilyNumber.get(`${family}:${number}`);\n if (byFamily) return [...byFamily];\n }\n\n return [];\n}\n\n/* -------------------------------------------------------------------------- */\n/* Near misses */\n/* -------------------------------------------------------------------------- */\n\n/**\n * The one document a failed reference was probably meant to name.\n *\n * A suggestion is cheap to read and expensive to get wrong: \"did you mean\n * ADR-0008?\" against a citation that meant ADR-0012 sends a reader to the wrong\n * decision with a confidence nobody earned. So the bar is not closeness, it is\n * closeness *in the part of the spelling that is not the identity*. A family\n * name is a word people misremember. A number is the identity itself, and\n * `ADR-0009` sits one edit from every neighbour it has - so numbers are never\n * guessed at, and a repository of fifteen ADRs citing a sixteenth is told the\n * plain truth instead.\n *\n * Two gates, plus a fallback:\n *\n * - a path in the right directory whose basename is one edit out - a typo;\n * - a family one edit out with its number intact - `ARD-0009` for `ADR-0009`.\n *\n * Anything else falls through to a one-edit match against the folded spellings\n * documents already answer to, which is where a mistyped slug or wiki name\n * lands.\n *\n * There is deliberately no gate for a file that moved. Resolution already binds\n * a path by its basename, so `../guides/onboarding.md` finds the document that\n * is now in `handbook/` without anybody being asked to confirm a guess - and a\n * suggestion nobody needs is a suggestion that can only be wrong.\n *\n * Every gate ends the same way: **exactly one** candidate, or nothing. Two\n * suggestions is the ambiguity this module refuses to resolve anywhere else,\n * and the tail of a hint is no place to start.\n */\nfunction nearMisses(target: string, entry: ExtractedDocument, index: Index): string[] {\n if (looksLikePath(target)) {\n const resolved = resolveFrom(entry.document.path, target).toLowerCase();\n const stem = stemOf(resolved);\n const siblings = index.byDirectory.get(dirnamePosix(resolved)) ?? [];\n return sole(siblings.filter((file) => withinOneEdit(file.stem, stem)).map((file) => file.id));\n }\n\n const prefixed = parsePrefixedRef(target);\n if (prefixed !== null) {\n const hits: string[] = [];\n for (const family of index.families) {\n // The family as written needs no exclusion: one edit is never zero edits.\n if (!withinOneEdit(family.toLowerCase(), prefixed.family.toLowerCase())) continue;\n for (const id of index.byFamilyNumber.get(`${family}:${prefixed.number}`) ?? []) hits.push(id);\n }\n return sole(hits);\n }\n\n // A bare `12` carries nothing but a number, which is the one thing this\n // refuses to guess at.\n if (parseBareRef(target) !== null) return [];\n\n const key = normaliseRef(target);\n if (key.length < MIN_SUGGESTIBLE) return [];\n const hits: string[] = [];\n // Every bucketed spelling is a key of `byAlias`, so its `?? []` is for the\n // type; and a spelling in place of an empty bucket names no document here.\n for (const length of [key.length - 1, key.length, key.length + 1]) {\n for (const alias of index.aliasesByLength.get(length) ?? []) {\n if (!withinOneEdit(alias, key)) continue;\n for (const id of index.byAlias.get(alias) ?? []) hits.push(id);\n }\n }\n return sole(hits);\n}\n\n/**\n * How long a folded spelling has to be before one edit means anything.\n *\n * Below six characters an edit is most of the word, and every corpus is full of\n * short names that differ by exactly that much.\n */\nconst MIN_SUGGESTIBLE = 6;\n\n/** The candidates, if there is exactly one of them. Otherwise nothing. */\nfunction sole(ids: Iterable<string>): string[] {\n const unique = new Set(ids);\n return unique.size === 1 ? [...unique] : [];\n}\n\n/**\n * Which setting, if any, declared this reference none of the repository's\n * business.\n *\n * Returns the mechanism rather than a boolean so the audit trail can say which\n * line of configuration to go and look at. A team that silenced eight things\n * with one glob and one with a family needs to be told them apart.\n */\nfunction filteredBy(target: string, bare: string, options: ResolveOptions): SuppressedRef['by'] | null {\n if (options.isIgnoredReference?.(target)) return 'reference';\n const prefixed = parsePrefixedRef(bare);\n if (prefixed !== null && options.isIgnoredFamily?.(prefixed.family) === true) return 'family';\n return null;\n}\n\n/**\n * Whether an unresolved bare identifier deserves a report.\n *\n * Only when the corpus already contains that family. `ADR-0099` in a repository\n * of ADRs is a real dangling citation; `T-1000` in the same repository is a\n * sentence about a robot.\n */\nfunction worthReporting(target: string, index: Index): boolean {\n const prefixed = parsePrefixedRef(target);\n return prefixed !== null && index.families.has(prefixed.family);\n}\n\n/** True when a path-like target names a directory, as `../guides` can. */\nfunction isDirectoryPath(target: string, entry: ExtractedDocument, options: ResolveOptions): boolean {\n if (!looksLikePath(target) || !options.isDirectory) return false;\n return options.isDirectory(resolveFrom(entry.document.path, target));\n}\n\nfunction pathMissingReason(\n target: string,\n entry: ExtractedDocument,\n options: ResolveOptions,\n): DanglingRef['reason'] {\n if (!looksLikePath(target) || !options.fileExists) return 'unknown-target';\n const resolved = resolveFrom(entry.document.path, target);\n return options.fileExists(resolved) ? 'not-a-spec' : 'unknown-target';\n}\n\n/**\n * Binds a `#anchor` to an item or a section.\n *\n * Anchors are how a delegation names a specific obligation rather than a whole\n * document, so resolving them precisely is what lets a ghost-handover finding\n * say *which* question was handed into the archive.\n */\nfunction bindAnchor(\n candidate: ReferenceCandidate,\n documentId: string,\n anchor: string,\n index: Index,\n nodes: ReadonlyMap<string, SpecNode>,\n options: ResolveOptions,\n): Edge | DanglingRef | SuppressedRef | null {\n const itemId = `${documentId}#${anchor}`;\n if (index.itemIds.has(itemId)) return makeEdge(candidate, itemId);\n\n // Every document, a file or a region of one, registered its anchors, and a\n // document id here is always one of theirs.\n const anchors = index.anchors.get(documentId) as ReadonlySet<string>;\n if (anchors.has(anchor.toLowerCase())) return makeEdge(candidate, documentId);\n\n // Some renderers slugify differently; try the loosest reasonable match before\n // calling it broken.\n const loose = anchor.toLowerCase().replace(/[^\\p{L}\\p{N}]+/gu, '-').replace(/^-|-$/g, '');\n if (anchors.has(loose)) return makeEdge(candidate, documentId);\n\n const silenced = filteredBy(candidate.target, splitAnchor(candidate.target).target, options);\n if (silenced !== null) return suppression(candidate, silenced);\n\n const candidates = [...(nodes.keys() as Iterable<string>)].filter(\n (id) => id.startsWith(`${documentId}#`) && id.toLowerCase().includes(loose),\n );\n return {\n kind: candidate.kind,\n from: candidate.from,\n target: candidate.target,\n reason: 'unknown-anchor',\n origin: candidate.origin,\n declaredAt: candidate.declaredAt,\n raw: candidate.raw,\n candidates,\n };\n}\n\nfunction makeEdge(candidate: ReferenceCandidate, resolved: string): Edge {\n const from = candidate.inverted ? resolved : candidate.from;\n const to = candidate.inverted ? candidate.from : resolved;\n return {\n kind: candidate.kind,\n from,\n to,\n origin: candidate.origin,\n declaredAt: candidate.declaredAt,\n raw: candidate.raw,\n declaredIn: [candidate.declaredAt.file],\n reflexive: documentOf(from) === documentOf(to),\n };\n}\n\nfunction suppression(candidate: ReferenceCandidate, by: SuppressedRef['by']): SuppressedRef {\n return { target: candidate.target, from: candidate.from, at: candidate.declaredAt, by };\n}\n\nfunction dangle(\n candidate: ReferenceCandidate,\n reason: DanglingRef['reason'],\n candidates: readonly string[],\n): DanglingRef {\n return {\n kind: candidate.kind,\n from: candidate.from,\n target: candidate.target,\n reason,\n origin: candidate.origin,\n declaredAt: candidate.declaredAt,\n raw: candidate.raw,\n candidates,\n };\n}\n\n/** The document part of a node id: `ADR-7#q.1` -> `ADR-7`. */\nexport function documentOf(nodeId: string): string {\n const hash = nodeId.indexOf('#');\n return hash === -1 ? nodeId : nodeId.slice(0, hash);\n}\n"]}
package/dist/runner.d.ts CHANGED
@@ -86,6 +86,10 @@ export declare function createHistoryMatcher(patterns: readonly string[] | undef
86
86
  * prose. A denylist handles the narrower case where the corpus genuinely owns a
87
87
  * family but some of its numbers belong to somebody else, which is exactly
88
88
  * `RFC 2119` in a repository of local RFCs.
89
+ *
90
+ * Throws for a name no family has, as a pattern that is no glob throws: an
91
+ * allowlist holding only `''` or `'ADR,RFC'` allowed nothing, and every
92
+ * dangling citation went unreported.
89
93
  */
90
94
  export declare function createFamilyFilter(families: readonly string[] | undefined, ignoreFamilies: readonly string[] | undefined): ((family: string) => boolean) | undefined;
91
95
  interface Analysed {
package/dist/runner.js CHANGED
@@ -11,6 +11,7 @@ import { readFile } from 'node:fs/promises';
11
11
  import { extractSpecifications } from './extract.js';
12
12
  import { createGlobMatcher, createReferenceFilter, walkFiles } from './glob.js';
13
13
  import { buildGraph } from './graph.js';
14
+ import { isFamilyName } from './identity.js';
14
15
  import { toPosix } from './paths.js';
15
16
  import { resolveCorpus } from './resolve.js';
16
17
  import { runRules } from './rules.js';
@@ -79,8 +80,16 @@ export function createHistoryMatcher(patterns) {
79
80
  * prose. A denylist handles the narrower case where the corpus genuinely owns a
80
81
  * family but some of its numbers belong to somebody else, which is exactly
81
82
  * `RFC 2119` in a repository of local RFCs.
83
+ *
84
+ * Throws for a name no family has, as a pattern that is no glob throws: an
85
+ * allowlist holding only `''` or `'ADR,RFC'` allowed nothing, and every
86
+ * dangling citation went unreported.
82
87
  */
83
88
  export function createFamilyFilter(families, ignoreFamilies) {
89
+ for (const name of [...(families ?? []), ...(ignoreFamilies ?? [])]) {
90
+ if (!isFamilyName(name))
91
+ throw new Error(`"${name}" is not a family's name, such as ADR`);
92
+ }
84
93
  const allowed = families && families.length > 0 ? new Set(families.map((f) => f.trim().toUpperCase())) : null;
85
94
  const denied = new Set((ignoreFamilies ?? []).map((f) => f.trim().toUpperCase()));
86
95
  if (allowed === null && denied.size === 0)
@@ -1 +1 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAA0B,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,UAAU,EAAkB,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAGxD,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC/D,cAAc;IACd,aAAa;IACb,aAAa;IACb,cAAc;IACd,eAAe;IACf,MAAM;CACP,CAAC,CAAC;AAEH,uCAAuC;AACvC,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AA4CtC,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAuB;IACnD,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAClC,wEAAwE;IACxE,yEAAyE;IACzE,0EAA0E;IAC1E,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAsB,EAAE,WAAkC;IACxF,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAC9C,KAAK,MAAM,UAAU,IAAI,WAAW;QAAE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvE,OAAO;QACL,GAAG,MAAM;QACT,WAAW;QACX,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE;QAC/F,EAAE,EAAE,MAAM,CAAC,KAAK,KAAK,CAAC;KACvB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Orchestration: files in, graph and findings out.\n *\n * The only part of spec-graph that touches the filesystem. Everything below it\n * is a pure function of text, which is why the test suite can build pathological\n * corpora in memory and why a build script can feed spec-graph documents that\n * never existed on disk.\n */\n\nimport { existsSync, statSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\n\nimport { extractSpecifications, type ExtractedDocument } from './extract.js';\nimport { createGlobMatcher, createReferenceFilter, walkFiles, type WalkedFile } from './glob.js';\nimport { buildGraph, type SpecGraph } from './graph.js';\nimport { toPosix } from './paths.js';\nimport { resolveCorpus, type ResolvedCorpus } from './resolve.js';\nimport type { ProjectRule } from './project-rules.js';\nimport { runRules, type RuleOptions } from './rules.js';\nimport type { AnalysisSummary, AnyRuleId, Diagnostic, ParseProblem, Severity } from './types.js';\n\n/** Patterns used when the caller names none. */\nexport const DEFAULT_PATTERNS: readonly string[] = Object.freeze([\n 'docs/**/*.md',\n 'doc/**/*.md',\n 'adr/**/*.md',\n 'rfcs/**/*.md',\n 'specs/**/*.md',\n '*.md',\n]);\n\n/** How many files are read at once. */\nexport const DEFAULT_CONCURRENCY = 16;\n\nexport interface AnalyseOptions {\n /** Absolute or relative directory the patterns are resolved against. */\n readonly root: string;\n readonly patterns?: readonly string[] | undefined;\n readonly ignore?: readonly string[] | undefined;\n /**\n * Reference targets to leave unreported when they do not resolve.\n *\n * For repositories where `[[...]]` tags concepts rather than naming files.\n * Suppresses findings only; a reference that resolves is still an edge.\n */\n readonly ignoreReferences?: readonly string[] | undefined;\n /** Families a bare identifier may name. Unset means any family in the corpus. */\n readonly families?: readonly string[] | undefined;\n /** Families that are never citations, whatever the corpus contains. */\n readonly ignoreFamilies?: readonly string[] | undefined;\n /**\n * Files that are logs of what was decided rather than decisions.\n *\n * Journals, changelogs, meeting minutes, sprint summaries. Their references\n * are still checked; their obligations and lifecycle are not. See ADR-0011.\n */\n readonly historyPatterns?: readonly string[] | undefined;\n readonly severities?: Partial<Record<AnyRuleId, Severity>> | undefined;\n /** Conventions the repository wrote for itself. See ADR-0016. */\n readonly projectRules?: readonly ProjectRule[] | undefined;\n readonly concurrency?: number | undefined;\n readonly maxRelated?: number | undefined;\n readonly followSymlinks?: boolean | undefined;\n}\n\nexport interface AnalysisResult {\n readonly graph: SpecGraph;\n readonly corpus: ResolvedCorpus;\n readonly diagnostics: readonly Diagnostic[];\n readonly problems: readonly ParseProblem[];\n readonly files: readonly string[];\n readonly summary: AnalysisSummary;\n /** True when nothing at error severity was found. */\n readonly ok: boolean;\n}\n\n/** Reads, extracts, resolves, and checks a corpus of specifications. */\nexport async function analyse(options: AnalyseOptions): Promise<AnalysisResult> {\n const started = performance.now();\n // The walk strips the root again, and past it the root only prefixes an\n // existence check, where `docs//x.md` names what `docs/x.md` does - so a\n // mutant that strips one separator rather than all of them is equivalent.\n const root = toPosix(options.root).replace(/\\/+$/, '');\n const patterns = options.patterns && options.patterns.length > 0 ? options.patterns : DEFAULT_PATTERNS;\n\n const walked = await walkFiles({\n root,\n patterns,\n ignore: options.ignore,\n followSymlinks: options.followSymlinks,\n });\n\n const sources = await readAll(walked, options.concurrency ?? DEFAULT_CONCURRENCY);\n const present = new Set(walked.map((file) => file.path.toLowerCase()));\n\n return finish(\n analyseSources(sources, {\n // Consulted only for references that failed to resolve, so the cost is\n // bounded by the number of findings - and it buys the difference between\n // \"that document does not exist\" and \"that document exists but your\n // include patterns did not reach it\", which are different fixes.\n fileExists: (path) => present.has(path.toLowerCase()) || existsSync(`${root}/${path}`),\n isDirectory: (path) => statSync(`${root}/${path}`, { throwIfNoEntry: false })?.isDirectory() === true,\n // A stray entry in the empty fallback changes a run only for a reference\n // whose target it matches, so the mutant that plants one survives every\n // corpus but one written for it.\n isIgnoredReference: createReferenceFilter(options.ignoreReferences ?? []),\n isIgnoredFamily: createFamilyFilter(options.families, options.ignoreFamilies),\n isRecord: createHistoryMatcher(options.historyPatterns),\n severities: options.severities,\n projectRules: options.projectRules,\n maxRelated: options.maxRelated,\n }),\n walked.map((file) => file.path),\n started,\n );\n}\n\nexport interface Source {\n /** Repository-relative POSIX path. */\n readonly path: string;\n readonly text: string;\n}\n\nexport interface AnalyseSourcesOptions extends RuleOptions {\n readonly fileExists?: ((path: string) => boolean) | undefined;\n readonly isDirectory?: ((path: string) => boolean) | undefined;\n readonly isIgnoredReference?: ((target: string) => boolean) | undefined;\n readonly isIgnoredFamily?: ((family: string) => boolean) | undefined;\n /** Whether a path holds a historical record rather than a specification. */\n readonly isRecord?: ((path: string) => boolean) | undefined;\n}\n\n/**\n * Builds the record predicate, or nothing when no patterns were given.\n *\n * Returning `undefined` rather than a predicate that always says no keeps the\n * common case free of a call per file, and makes \"no history patterns\" visible\n * as an absent option rather than as a function nobody can read.\n */\nexport function createHistoryMatcher(patterns: readonly string[] | undefined): ((path: string) => boolean) | undefined {\n if (patterns === undefined || patterns.length === 0) return undefined;\n return createGlobMatcher(patterns);\n}\n\n/**\n * Builds the family predicate from an allowlist and a denylist.\n *\n * An allowlist is the stronger statement - \"these are the families this\n * repository has\" - and turns every other noun-number construct back into\n * prose. A denylist handles the narrower case where the corpus genuinely owns a\n * family but some of its numbers belong to somebody else, which is exactly\n * `RFC 2119` in a repository of local RFCs.\n */\nexport function createFamilyFilter(\n families: readonly string[] | undefined,\n ignoreFamilies: readonly string[] | undefined,\n): ((family: string) => boolean) | undefined {\n const allowed = families && families.length > 0 ? new Set(families.map((f) => f.trim().toUpperCase())) : null;\n const denied = new Set((ignoreFamilies ?? []).map((f) => f.trim().toUpperCase()));\n if (allowed === null && denied.size === 0) return undefined;\n return (family: string): boolean => {\n const key = family.toUpperCase();\n if (denied.has(key)) return true;\n return allowed !== null && !allowed.has(key);\n };\n}\n\ninterface Analysed {\n readonly graph: SpecGraph;\n readonly corpus: ResolvedCorpus;\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * The whole engine, without a filesystem.\n *\n * Exported because it is the honest unit of composition: a monorepo tool that\n * already has the file contents in memory should not have to write them out to\n * a temporary directory to use spec-graph.\n */\nexport function analyseSources(sources: readonly Source[], options: AnalyseSourcesOptions = {}): Analysed {\n const extracted: ExtractedDocument[] = [];\n for (const source of sources) {\n extracted.push(\n ...extractSpecifications({\n path: source.path,\n text: source.text,\n record: options.isRecord?.(source.path) === true,\n }),\n );\n }\n\n const corpus = resolveCorpus(extracted, {\n fileExists: options.fileExists,\n isDirectory: options.isDirectory,\n isIgnoredReference: options.isIgnoredReference,\n isIgnoredFamily: options.isIgnoredFamily,\n });\n const graph = buildGraph({ nodes: corpus.nodes, edges: corpus.edges });\n const diagnostics = runRules(graph, corpus, options);\n return { graph, corpus, diagnostics };\n}\n\nfunction finish(analysed: Analysed, files: readonly string[], started: number): AnalysisResult {\n const { graph, corpus, diagnostics } = analysed;\n const counts = { error: 0, warn: 0, info: 0 };\n for (const diagnostic of diagnostics) counts[diagnostic.severity] += 1;\n const records = new Set(corpus.documents.filter((node) => node.phase === 'record').map((node) => node.id));\n\n const summary: AnalysisSummary = {\n documents: corpus.documents.length,\n items: corpus.items.length,\n edges: graph.edges.length,\n // A record's unchecked boxes are minutes, not work. Counting them would\n // make the headline number the one thing in the report nobody can act on.\n openObligations: corpus.items.filter((item) => item.openness !== 'closed' && !records.has(item.document)).length,\n errors: counts.error,\n warnings: counts.warn,\n infos: counts.info,\n durationMs: Math.round((performance.now() - started) * 100) / 100,\n };\n\n return {\n graph,\n corpus,\n diagnostics,\n problems: corpus.problems,\n files,\n summary,\n ok: counts.error === 0,\n };\n}\n\n/** Reads files with bounded concurrency, skipping ones that cannot be read. */\nasync function readAll(files: readonly WalkedFile[], concurrency: number): Promise<Source[]> {\n // Pre-sized for throughput only: the length is set to what was read below,\n // so an array that starts empty ends the same. That mutant is equivalent.\n const out: Source[] = new Array(files.length);\n let cursor = 0;\n let written = 0;\n\n const worker = async (): Promise<void> => {\n for (;;) {\n const index = cursor;\n cursor += 1;\n // `>` for `>=` lets one worker take the index past the end, whose read\n // throws inside the `try` below and is skipped like any unreadable file:\n // an equivalent mutant.\n if (index >= files.length) return;\n const file = files[index] as WalkedFile;\n try {\n const text = await readFile(file.absolute, 'utf8');\n out[written] = { path: file.path, text };\n written += 1;\n } catch {\n // A file that vanished or cannot be decoded is skipped, not fatal.\n }\n }\n };\n\n // How many workers there are, once there is one, changes throughput and\n // nothing a caller sees: one reads every file, and each worker past the last\n // file returns at once. The mutants that only move the count are equivalent,\n // and no test counts workers.\n const workers = Array.from({ length: Math.max(1, Math.min(concurrency, files.length || 1)) }, worker);\n await Promise.all(workers);\n out.length = written;\n // Deterministic order regardless of which worker finished first. The walk\n // hands over each path once, and the sort acts only on whether a comparison\n // is negative, so the mutants that change its answer for two equal paths, or\n // give 0 rather than 1 for a later one, sort the same.\n return out.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));\n}\n\n/**\n * Rebuilds a result around a narrower set of findings.\n *\n * The corpus, the graph and the counts of what is in them are unchanged - a\n * baseline suppresses findings, never facts. Only the tallies that describe the\n * findings, and the verdict that follows from them, move.\n */\nexport function withDiagnostics(result: AnalysisResult, diagnostics: readonly Diagnostic[]): AnalysisResult {\n const counts = { error: 0, warn: 0, info: 0 };\n for (const diagnostic of diagnostics) counts[diagnostic.severity] += 1;\n return {\n ...result,\n diagnostics,\n summary: { ...result.summary, errors: counts.error, warnings: counts.warn, infos: counts.info },\n ok: counts.error === 0,\n };\n}\n"]}
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAA0B,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,UAAU,EAAkB,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAGxD,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC/D,cAAc;IACd,aAAa;IACb,aAAa;IACb,cAAc;IACd,eAAe;IACf,MAAM;CACP,CAAC,CAAC;AAEH,uCAAuC;AACvC,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AA4CtC,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAuB;IACnD,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;I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**\n * Orchestration: files in, graph and findings out.\n *\n * The only part of spec-graph that touches the filesystem. Everything below it\n * is a pure function of text, which is why the test suite can build pathological\n * corpora in memory and why a build script can feed spec-graph documents that\n * never existed on disk.\n */\n\nimport { existsSync, statSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\n\nimport { extractSpecifications, type ExtractedDocument } from './extract.js';\nimport { createGlobMatcher, createReferenceFilter, walkFiles, type WalkedFile } from './glob.js';\nimport { buildGraph, type SpecGraph } from './graph.js';\nimport { isFamilyName } from './identity.js';\nimport { toPosix } from './paths.js';\nimport { resolveCorpus, type ResolvedCorpus } from './resolve.js';\nimport type { ProjectRule } from './project-rules.js';\nimport { runRules, type RuleOptions } from './rules.js';\nimport type { AnalysisSummary, AnyRuleId, Diagnostic, ParseProblem, Severity } from './types.js';\n\n/** Patterns used when the caller names none. */\nexport const DEFAULT_PATTERNS: readonly string[] = Object.freeze([\n 'docs/**/*.md',\n 'doc/**/*.md',\n 'adr/**/*.md',\n 'rfcs/**/*.md',\n 'specs/**/*.md',\n '*.md',\n]);\n\n/** How many files are read at once. */\nexport const DEFAULT_CONCURRENCY = 16;\n\nexport interface AnalyseOptions {\n /** Absolute or relative directory the patterns are resolved against. */\n readonly root: string;\n readonly patterns?: readonly string[] | undefined;\n readonly ignore?: readonly string[] | undefined;\n /**\n * Reference targets to leave unreported when they do not resolve.\n *\n * For repositories where `[[...]]` tags concepts rather than naming files.\n * Suppresses findings only; a reference that resolves is still an edge.\n */\n readonly ignoreReferences?: readonly string[] | undefined;\n /** Families a bare identifier may name. Unset means any family in the corpus. */\n readonly families?: readonly string[] | undefined;\n /** Families that are never citations, whatever the corpus contains. */\n readonly ignoreFamilies?: readonly string[] | undefined;\n /**\n * Files that are logs of what was decided rather than decisions.\n *\n * Journals, changelogs, meeting minutes, sprint summaries. Their references\n * are still checked; their obligations and lifecycle are not. See ADR-0011.\n */\n readonly historyPatterns?: readonly string[] | undefined;\n readonly severities?: Partial<Record<AnyRuleId, Severity>> | undefined;\n /** Conventions the repository wrote for itself. See ADR-0016. */\n readonly projectRules?: readonly ProjectRule[] | undefined;\n readonly concurrency?: number | undefined;\n readonly maxRelated?: number | undefined;\n readonly followSymlinks?: boolean | undefined;\n}\n\nexport interface AnalysisResult {\n readonly graph: SpecGraph;\n readonly corpus: ResolvedCorpus;\n readonly diagnostics: readonly Diagnostic[];\n readonly problems: readonly ParseProblem[];\n readonly files: readonly string[];\n readonly summary: AnalysisSummary;\n /** True when nothing at error severity was found. */\n readonly ok: boolean;\n}\n\n/** Reads, extracts, resolves, and checks a corpus of specifications. */\nexport async function analyse(options: AnalyseOptions): Promise<AnalysisResult> {\n const started = performance.now();\n // The walk strips the root again, and past it the root only prefixes an\n // existence check, where `docs//x.md` names what `docs/x.md` does - so a\n // mutant that strips one separator rather than all of them is equivalent.\n const root = toPosix(options.root).replace(/\\/+$/, '');\n const patterns = options.patterns && options.patterns.length > 0 ? options.patterns : DEFAULT_PATTERNS;\n\n const walked = await walkFiles({\n root,\n patterns,\n ignore: options.ignore,\n followSymlinks: options.followSymlinks,\n });\n\n const sources = await readAll(walked, options.concurrency ?? DEFAULT_CONCURRENCY);\n const present = new Set(walked.map((file) => file.path.toLowerCase()));\n\n return finish(\n analyseSources(sources, {\n // Consulted only for references that failed to resolve, so the cost is\n // bounded by the number of findings - and it buys the difference between\n // \"that document does not exist\" and \"that document exists but your\n // include patterns did not reach it\", which are different fixes.\n fileExists: (path) => present.has(path.toLowerCase()) || existsSync(`${root}/${path}`),\n isDirectory: (path) => statSync(`${root}/${path}`, { throwIfNoEntry: false })?.isDirectory() === true,\n // A stray entry in the empty fallback changes a run only for a reference\n // whose target it matches, so the mutant that plants one survives every\n // corpus but one written for it.\n isIgnoredReference: createReferenceFilter(options.ignoreReferences ?? []),\n isIgnoredFamily: createFamilyFilter(options.families, options.ignoreFamilies),\n isRecord: createHistoryMatcher(options.historyPatterns),\n severities: options.severities,\n projectRules: options.projectRules,\n maxRelated: options.maxRelated,\n }),\n walked.map((file) => file.path),\n started,\n );\n}\n\nexport interface Source {\n /** Repository-relative POSIX path. */\n readonly path: string;\n readonly text: string;\n}\n\nexport interface AnalyseSourcesOptions extends RuleOptions {\n readonly fileExists?: ((path: string) => boolean) | undefined;\n readonly isDirectory?: ((path: string) => boolean) | undefined;\n readonly isIgnoredReference?: ((target: string) => boolean) | undefined;\n readonly isIgnoredFamily?: ((family: string) => boolean) | undefined;\n /** Whether a path holds a historical record rather than a specification. */\n readonly isRecord?: ((path: string) => boolean) | undefined;\n}\n\n/**\n * Builds the record predicate, or nothing when no patterns were given.\n *\n * Returning `undefined` rather than a predicate that always says no keeps the\n * common case free of a call per file, and makes \"no history patterns\" visible\n * as an absent option rather than as a function nobody can read.\n */\nexport function createHistoryMatcher(patterns: readonly string[] | undefined): ((path: string) => boolean) | undefined {\n if (patterns === undefined || patterns.length === 0) return undefined;\n return createGlobMatcher(patterns);\n}\n\n/**\n * Builds the family predicate from an allowlist and a denylist.\n *\n * An allowlist is the stronger statement - \"these are the families this\n * repository has\" - and turns every other noun-number construct back into\n * prose. A denylist handles the narrower case where the corpus genuinely owns a\n * family but some of its numbers belong to somebody else, which is exactly\n * `RFC 2119` in a repository of local RFCs.\n *\n * Throws for a name no family has, as a pattern that is no glob throws: an\n * allowlist holding only `''` or `'ADR,RFC'` allowed nothing, and every\n * dangling citation went unreported.\n */\nexport function createFamilyFilter(\n families: readonly string[] | undefined,\n ignoreFamilies: readonly string[] | undefined,\n): ((family: string) => boolean) | undefined {\n for (const name of [...(families ?? []), ...(ignoreFamilies ?? [])]) {\n if (!isFamilyName(name)) throw new Error(`\"${name}\" is not a family's name, such as ADR`);\n }\n const allowed = families && families.length > 0 ? new Set(families.map((f) => f.trim().toUpperCase())) : null;\n const denied = new Set((ignoreFamilies ?? []).map((f) => f.trim().toUpperCase()));\n if (allowed === null && denied.size === 0) return undefined;\n return (family: string): boolean => {\n const key = family.toUpperCase();\n if (denied.has(key)) return true;\n return allowed !== null && !allowed.has(key);\n };\n}\n\ninterface Analysed {\n readonly graph: SpecGraph;\n readonly corpus: ResolvedCorpus;\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * The whole engine, without a filesystem.\n *\n * Exported because it is the honest unit of composition: a monorepo tool that\n * already has the file contents in memory should not have to write them out to\n * a temporary directory to use spec-graph.\n */\nexport function analyseSources(sources: readonly Source[], options: AnalyseSourcesOptions = {}): Analysed {\n const extracted: ExtractedDocument[] = [];\n for (const source of sources) {\n extracted.push(\n ...extractSpecifications({\n path: source.path,\n text: source.text,\n record: options.isRecord?.(source.path) === true,\n }),\n );\n }\n\n const corpus = resolveCorpus(extracted, {\n fileExists: options.fileExists,\n isDirectory: options.isDirectory,\n isIgnoredReference: options.isIgnoredReference,\n isIgnoredFamily: options.isIgnoredFamily,\n });\n const graph = buildGraph({ nodes: corpus.nodes, edges: corpus.edges });\n const diagnostics = runRules(graph, corpus, options);\n return { graph, corpus, diagnostics };\n}\n\nfunction finish(analysed: Analysed, files: readonly string[], started: number): AnalysisResult {\n const { graph, corpus, diagnostics } = analysed;\n const counts = { error: 0, warn: 0, info: 0 };\n for (const diagnostic of diagnostics) counts[diagnostic.severity] += 1;\n const records = new Set(corpus.documents.filter((node) => node.phase === 'record').map((node) => node.id));\n\n const summary: AnalysisSummary = {\n documents: corpus.documents.length,\n items: corpus.items.length,\n edges: graph.edges.length,\n // A record's unchecked boxes are minutes, not work. Counting them would\n // make the headline number the one thing in the report nobody can act on.\n openObligations: corpus.items.filter((item) => item.openness !== 'closed' && !records.has(item.document)).length,\n errors: counts.error,\n warnings: counts.warn,\n infos: counts.info,\n durationMs: Math.round((performance.now() - started) * 100) / 100,\n };\n\n return {\n graph,\n corpus,\n diagnostics,\n problems: corpus.problems,\n files,\n summary,\n ok: counts.error === 0,\n };\n}\n\n/** Reads files with bounded concurrency, skipping ones that cannot be read. */\nasync function readAll(files: readonly WalkedFile[], concurrency: number): Promise<Source[]> {\n // Pre-sized for throughput only: the length is set to what was read below,\n // so an array that starts empty ends the same. That mutant is equivalent.\n const out: Source[] = new Array(files.length);\n let cursor = 0;\n let written = 0;\n\n const worker = async (): Promise<void> => {\n for (;;) {\n const index = cursor;\n cursor += 1;\n // `>` for `>=` lets one worker take the index past the end, whose read\n // throws inside the `try` below and is skipped like any unreadable file:\n // an equivalent mutant.\n if (index >= files.length) return;\n const file = files[index] as WalkedFile;\n try {\n const text = await readFile(file.absolute, 'utf8');\n out[written] = { path: file.path, text };\n written += 1;\n } catch {\n // A file that vanished or cannot be decoded is skipped, not fatal.\n }\n }\n };\n\n // How many workers there are, once there is one, changes throughput and\n // nothing a caller sees: one reads every file, and each worker past the last\n // file returns at once. The mutants that only move the count are equivalent,\n // and no test counts workers.\n const workers = Array.from({ length: Math.max(1, Math.min(concurrency, files.length || 1)) }, worker);\n await Promise.all(workers);\n out.length = written;\n // Deterministic order regardless of which worker finished first. The walk\n // hands over each path once, and the sort acts only on whether a comparison\n // is negative, so the mutants that change its answer for two equal paths, or\n // give 0 rather than 1 for a later one, sort the same.\n return out.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));\n}\n\n/**\n * Rebuilds a result around a narrower set of findings.\n *\n * The corpus, the graph and the counts of what is in them are unchanged - a\n * baseline suppresses findings, never facts. Only the tallies that describe the\n * findings, and the verdict that follows from them, move.\n */\nexport function withDiagnostics(result: AnalysisResult, diagnostics: readonly Diagnostic[]): AnalysisResult {\n const counts = { error: 0, warn: 0, info: 0 };\n for (const diagnostic of diagnostics) counts[diagnostic.severity] += 1;\n return {\n ...result,\n diagnostics,\n summary: { ...result.summary, errors: counts.error, warnings: counts.warn, infos: counts.info },\n ok: counts.error === 0,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descent-vtt/spec-graph",
3
- "version": "0.13.1",
3
+ "version": "0.14.1",
4
4
  "description": "Turn Markdown specs into a verifiable relational graph. Catches ghost handovers, stale premises and broken references in CI.",
5
5
  "keywords": [
6
6
  "adr",