/** * `docs_wikilinks` — derive + query the slug-addressed docs edge table. * * Per the ratified Docs-SSoT model (saga T11778) `cleo.db` is the SOLE doc * authority and `docs_wikilinks` is a **DERIVED, non-authoritative** edge table * reconstructed from three provenance columns already on `attachments`: * * - `supersedes` / `superseded_by` → doc→doc supersession edges * - `related_tasks` → doc→T#### task edges (JSON array) * - `topics` → doc↔doc shared-topic edges (JSON array) * * No markdown body `[[link]]` parsing is performed (T11826 AC4) — the edges * derive purely from structured columns. The derivation is **idempotent**: it * truncates and rebuilds the whole table, so callers may re-run it after any * `docs add` / `supersede` / `docs update` write to keep the graph fresh. * * This module is the runtime twin of the SQL backfill in * `migrations/drizzle-tasks/20260605000001_t11826-docs-wikilinks/migration.sql` * — the migration seeds the table on schema upgrade, this function rebuilds it * on demand. * * @task T11826 (Epic T11781 / Saga T11778) * @adr ADR-078 — Docs SSoT as provenance graph * @see build-provenance-graph.ts — the on-the-fly BFS this table makes O(edges) */ import { type DocsWikilinkRelation } from '../store/schema/attachments.js'; /** * A single slug-addressed wikilink edge. * * @task T11826 */ export interface WikilinkEdge { /** Source doc slug (always a doc). */ readonly fromSlug: string; /** Target slug — a doc slug, or a `T####` task id when {@link toIsTask}. */ readonly toSlug: string; /** Which provenance column produced this edge. */ readonly relation: DocsWikilinkRelation; /** True when {@link toSlug} is a task id (`related-task` edges). */ readonly toIsTask: boolean; } /** * Options shared by {@link rebuildDocsWikilinks}. * * @task T11826 */ export interface RebuildDocsWikilinksOptions { /** Project root for DB resolution. Defaults to {@link getProjectRoot}(). */ readonly projectRoot?: string; } /** * Outcome of a {@link rebuildDocsWikilinks} call. * * @task T11826 */ export interface RebuildDocsWikilinksResult { /** Number of edges in the table after the rebuild. */ readonly edgeCount: number; /** Per-relation edge counts. */ readonly byRelation: Readonly>; } /** Narrow row shape read from `attachments` during derivation. */ interface DerivationRow { readonly slug: string; readonly supersedesSlug: string | null; readonly supersededBySlug: string | null; readonly relatedTasks: string | null; readonly topics: string | null; } /** * Idempotently rebuild the `docs_wikilinks` edge table from the provenance * columns on `attachments`. * * The whole table is truncated and re-derived inside a single transaction, so * the function is safe to call after any doc write and always converges to the * same edge set for a given `attachments` state. * * @example * ```ts * const { edgeCount, byRelation } = await rebuildDocsWikilinks(); * console.log(`derived ${edgeCount} edges (${byRelation['topic']} topic links)`); * ``` * * @param opts - Optional project-root override. * @returns Edge totals after the rebuild. * @task T11826 */ export declare function rebuildDocsWikilinks(opts?: RebuildDocsWikilinksOptions): Promise; /** * Pure derivation: turn slugged `attachments` rows into the full edge set. * * Exposed for unit testing the derivation rules without a database. The output * is deduplicated on the (`fromSlug`, `toSlug`, `relation`) composite key. * * @param rows - Slugged attachment rows with their provenance columns. * @returns The derived wikilink edges. * @task T11826 */ export declare function deriveWikilinkEdges(rows: readonly DerivationRow[]): WikilinkEdge[]; /** * Read all wikilink edges incident to a doc slug — **bidirectional** by default. * * Returns both outbound edges (`from_slug = slug`) and inbound backlinks * (`to_slug = slug`). This is the query the Obsidian plugin (T11827) renders to * show a doc's neighborhood, and what `cleo docs graph` hydrates for persisted * backlinks. * * @param slug - The doc slug to fetch edges for. * @param opts.direction - `'both'` (default), `'out'`, or `'in'`. * @param opts.projectRoot - Project root override. * @returns The incident edges. * @task T11826 */ export declare function getDocsWikilinks(slug: string, opts?: { direction?: 'both' | 'out' | 'in'; projectRoot?: string; }): Promise; export {}; //# sourceMappingURL=wikilinks.d.ts.map