@haneinfo/references
v0.2.8
Published
Directed, typed links between objects with permission-filtered reverse lookups, preview cards and bounded impact graphs.
Readme
@haneinfo/references
Optional backend for directed, typed links between objects: reverse lookups, preview cards and a bounded impact graph, all filtered by the caller's read access. Implements approved decision 202610-f7a2. No frontend is included.
Identifiers
An object is { type, id } in HTTP and storage, and <type>:<id> in MCP and display. type is
lowercase letters and digits in hyphen-separated words (at most 64 characters); id is opaque,
1–128 code points without whitespace, control or format characters. The type ends at the first
colon, so ids may contain colons. parseObjectRef, formatObjectRef and the shared
OBJECT_REF_TEST_VECTORS live in @haneinfo/plugin-api.
The first version links StateMachine instances only (state-machine-instance). Other types can be
added later by registering an ObjectTypeProvider without changing the table.
Kinds
| Kind | Symmetric | Meaning |
| --- | --- | --- |
| relatesTo | yes | Related, no direction |
| derivedFrom | no | The source was derived from the target |
| blocks | no | The source blocks the target |
| supersedes | no | The source replaces the target |
Plugins declare more through the optional LINK_KINDS registry (register({ code, label,
symmetric })); codes are lowercase-first camelCase words, optionally dotted (loan.replaces).
Duplicate or invalid declarations fail startup. For a symmetric kind, creating B→A when A→B exists
returns the existing link.
Permissions
| Action | Rule |
| --- | --- |
| See an object's links | Read the object (otherwise 404); each link appears only when its other end is readable too |
| Create a link | Write the source (submitter, state-machine:instance:write, or a WRITE access entry) and read the target |
| Remove a link | Its creator, anyone who can write the source, or references:link:admin |
Soft-deleted instances are never readable, so they cannot be linked and their links disappear until
the instance is restored. Archived instances stay readable and linkable. Unreadable, deleted,
missing and unknown-type objects all return the same OBJECT_NOT_FOUND. A caller who cannot see a
link (an end is unreadable) and may not remove it gets LINK_NOT_FOUND, never FORBIDDEN.
HTTP
All routes use InteractiveAuthGuard.
| Route | Description |
| --- | --- |
| GET /references/objects/:type/:id/links?direction=out\|in\|both&kind=&limit=&cursor= | { items: [{ link, other }], nextCursor }, newest first; other is the card of the end that is not :type/:id. Default both, 50 per page, at most 200 |
| GET /references/objects/:type/:id/graph?direction=&kinds=a,b&depth= | { root, nodes, edges, truncated }; breadth-first, depth default 2 and at most 3; nodes carry their depth |
| POST /references/links | { from: { type, id }, to: { type, id }, kind, note? } → the link; 201 when created, 200 when the identical link already existed (unchanged) |
| DELETE /references/links/:id | 204 |
A link is { id, from, to, kind, note, createdBy, createdAt }. A preview card is { type, id,
title, subtitle?, state?, stateLabel?, archived?, path }; for an instance the title is its first
application number (or the machine name and UTC creation date), the subtitle the submitter's active
display name, and the path /instances/<id>. Card text and notes are user content: render them as
text.
The graph only expands nodes the caller can read: an unreadable node is never added, and anything
reachable only through it stays invisible. Nodes are capped at 200 and edges at 500; truncated
is true when a cap (or the per-level scan cap of 4,000 rows) cut the graph short. Edges are only
returned when both ends are nodes.
Notes are trimmed, at most 500 code points, without control characters other than newline and tab.
Each object may be the source of 100 and the target of 100 links (all kinds, readable or not);
creating one more returns LINK_LIMIT_EXCEEDED. Creation locks both ends with transaction-scoped
advisory locks so the limits and idempotency hold under concurrency.
| Code | Status | When |
| --- | --- | --- |
| LINK_INVALID | 400 | Malformed body, reference or query, self link, invalid note or cursor |
| LINK_KIND_UNKNOWN | 400 | The kind (or a kind/kinds filter) is not declared |
| OBJECT_NOT_FOUND | 404 | An end is missing, deleted, unreadable or of an unknown type |
| LINK_LIMIT_EXCEEDED | 409 | The source's outgoing or the target's incoming limit is reached |
| LINK_NOT_FOUND | 404 | The link does not exist or is not visible |
| FORBIDDEN | 403 | Visible, but the caller may not write the source or remove the link |
Timeline and events
Creating and removing a link adds a REFERENCE history entry (shown as REFERENCE in the
collaboration timeline) on each instance end, with decision.reference = { action: LINKED |
UNLINKED, linkId, kind, direction: out | in, other: { type, id, number } }. An end only gets the
entry when every principal reading it through its submitter or access list (users, and role members
through RBAC) can read the other end; otherwise the entry is written only on the end where that
holds, or nowhere. The same transaction publishes one references.linked or references.unlinked
runtime event (linkId, kind, from, to, userId, ISO at, historyIds). No notification
is sent. Permanent purge deletes the purged instance's edges in the purge transaction without
history entries or events.
MCP
| Tool | Scope | Description |
| --- | --- | --- |
| list_links | <namespace>:references:read | { object: "<type>:<id>", direction?, kind?, limit?, cursor? } |
| get_link_graph | <namespace>:references:read | { object, direction?, kinds?, depth? } |
| create_link | <namespace>:references:write | { from, to, kind, note? } → { created, link } |
Every tool needs a user-bound credential and runs the HTTP checks for that user. References are
strings; titles, subtitles, states, state labels and notes are wrapped as $userContent. There is
no removal tool.
Configuration
runtime.references (no secrets):
| Key | Default | Range |
| --- | --- | --- |
| maxOutgoingPerObject | 100 | 1–1,000 |
| maxIncomingPerObject | 100 | 1–1,000 |
| defaultPageSize | 50 | 1–200, ≤ maxPageSize |
| maxPageSize | 200 | 1–200 |
| defaultGraphDepth | 2 | 1–3, ≤ maxGraphDepth |
| maxGraphDepth | 3 | 1–3 |
| maxGraphNodes | 200 | 1–1,000 |
| maxGraphEdges | 500 | 1–5,000 |
| maxNoteLength | 500 | 1–2,000 |
Database
Include prisma/references.prisma and apply prisma/references.sql in an App migration. The
object_links table has no foreign keys (object types are generic): unique
(from_type, from_id, to_type, to_id, kind), indexes (from_type, from_id, created_at) and
(to_type, to_id, created_at), and a CHECK refusing self links. Deleting instance rows outside the
state-machine purge flow leaves orphan edges; they stay invisible because their end is unreadable.
Adding an object type
Inject the optional OBJECT_TYPE_PROVIDERS registry and register an ObjectTypeProvider during
module initialization: batched readableIds, writableIds and previewFor that apply the type's
own read rules and silently omit missing or unreadable ids, plus optional recordLinkActivity and
onPermanentlyRemoved. List haneinfo.references in the manifest's optionalRequires.
