* feat(entities): stub companies from the relation graph, and a lab entity kind Stub companies: every minted company:<slug> node a stated or corroborated relation touches (1,188 today; NAC Kazatomprom JSC, JV Inkai LLP, Uranium One Inc.) becomes an entity built from the graph at load, with evidence "stub", a page on the existing /markets/[slug] route that lists only the relations naming it (grade, quote, source), and the note that no profile is held. Rendered on demand, so the static page count is unchanged. The graph's producers resolve against the directory only (resolveInDirectory), so the stubs never change the graph they come from. Search and retrieval rank stubs at 0.6 and leave word rarity to full-weight documents, so profiled rankings do not move. Events and relations may name a stub; ownership and facility operator fields stay directory-only. Reviewed aliases redirect to the canonical page. Labs: a closed-set `lab` kind (allowEmpty until the pilot fills it), the labs candidate facet with schema and add.ts gate, a /labs/[slug] profile (what it works on, where and how to join, stated funders from finances relations), the lab dossier on lab:<id> with research fronts kept as their own science kind, and the country people_labs box counting lab rows. Seeds no lab data. Person is not added: the ADR pins it for office and board holders, not lab staff. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE * test(stubs): assert the summary's invariants, not its tail Main now carries the pilot's Kazatomprom relations, so its stub summary names a second source and the shipments. The test keeps what must hold: the yearbook leads, the stakes and the shipments are named. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE --------- Co-authored-by: Claude <noreply@anthropic.com>
4.5 KiB
lib/graph — the relation graph
Typed, sourced, dated edges between entities. The shapes are in types.ts
(Relation, EvidenceGrade, RELATION_TYPES); the design is
docs/architecture/2026-10-24-research-systems.md §2–3.
A relation has a source, a quote and a date, or it does not exist.
validate.ts enforces it on load and throws: stated needs one source with a
quote, corroborated two different sources, derived its derivedFrom chain
and rule (never resting on a lead), and lead is never counted.
Read API (import … from '@/lib/graph/index')
Import the folder's index explicitly: @/lib/graph resolves to the older
lib/graph.ts adapter, not to this folder.
| Call | Returns |
|---|---|
relationsFrom(id, { type?, minGrade?, origin? }) |
edges leaving id (what it operates, owns) |
relationsTo(id, …) |
edges arriving at id (who operates or owns it) |
neighbours(id, …) |
each neighbour as { node, relation, direction } |
pathsBetween(a, b, { maxHops = 3, limit = 20, … }) |
simple paths, shortest first, either direction |
relationEvidence(r) |
what a page prints: sentence, grade label, counted share, every source with quote, locator and reading; a derived relation's rule and chain |
graphNode(id) |
a name for any endpoint, including minted ones with no entity |
isCounted(r), countedShare(r) |
the only way a number may read a relation: stated and corroborated only |
graphStats() |
counts, conflicts, what the producers skipped |
minGrade: 'stated' keeps stated and corroborated. origin is curated,
candidate (not yet promoted) or research (parsed by a committed script).
An endpoint not in the directory is a minted company:<slug> or
facility:usgs-<site>. A minted company that a counted relation touches is a
stub company (lib/entities/sources/company-stubs.ts): an entity with a
page at /markets/<slug> that lists only the relations naming it, ranked below
profiled companies in search. The graph's own producers resolve names against
the directory only (resolveInDirectory), so the stubs never change the graph
they are built from.
Three ways to add an edge
- A candidate row. Write a JSON row and run
pnpm exec tsx scripts/research/add.ts relations rows.json --dry-run(--schemaprints the shape). The quote must appear on the source page; the endpoints must already exist on the site or inresearch/usgs-relations.json. Rows land inconfig/candidates/relations.json. A source adapter can draft these rows for you, quotes included:pnpm exec tsx scripts/research/run-task.ts <task-id>(lib/sources/README.md). - A row the corpus already holds. Ownership holders and facility
operators are read by
from-corpus.ts; add the holder or the operator to its config file with its source, and the edge follows. - A research file parsed by a script.
usgs-operators.tsreads the USGS yearbook cells;scripts/research/build-usgs-relations.tswritesresearch/usgs-relations.jsonwith a report of every string it left unparsed and why. Never edit that file by hand: change the parser and re-run the script (test/graph.test.tsfails when the file is stale).
A hand-written relation with no other home goes in config/substrata-relations.ts.
Rule proposals (research/derived-relations.json, written by
pnpm run research:derived-relations from lib/coverage/rules.ts) are
derived or lead only, carry their rule and chain, and load into
store.proposals — validated, but never walked, counted or indexed.
proposalsFor(id) reads them. shares_parent_with and may_be_same_as are
rule-only types and are always leads.
One organisation, one node
A minted id comes from the name a source printed, so a typesetting slip
("NAC Kazatomp JSC") is a second node. pnpm run research:alias-candidates
proposes pairs by named rules (alias-match.ts: legal form, spacing, a word
cut short within one country, transliteration) with the evidence for each;
nothing merges until the pair is written into config/entity-aliases.ts with
a one-line reason from the rows. aliases.ts applies the table — in the USGS
parser (re-run research:usgs-relations) and in the store for every other
producer. A subsidiary is never an alias of its parent.
find.ts turns a typed name into a node (directory, then the exact name
without legal forms, then every typed word); the chat tools related_to and
how_connected (lib/chat-tools/graph.ts) read the graph through it.