Wiki Export — Knowledge Graph Export skill
Export the Obsidian wiki's knowledge graph to structured formats for use in external tools.
by Ar9av·MIT license·★ 3,520 Stars on the repo·GitHub ↗
npx degit Ar9av/obsidian-wiki/.skills/wiki-export#main ~/.claude/skills/wiki-exportChecked ·commit main
Files of Wiki Export — Knowledge Graph Export
Show the full text449 lines
Wiki Export — Knowledge Graph Export
You are exporting the wiki's wikilink graph to structured formats so it can be used in external tools (Gephi, Neo4j, custom scripts, browser visualization).
Before You Start
- Resolve config — follow the Config Resolution Protocol in
llm-wiki/SKILL.md(inline@nameoverride → walk up CWD for.env→ global config → prompt setup). This givesOBSIDIAN_VAULT_PATH - Confirm the vault has pages to export — if fewer than 5 pages exist, warn the user and stop
Project Filter (optional)
If the user's invocation includes a project name — e.g. /wiki-export prismor, "export the prismor project", "export project:security" — activate project filter mode:
- Extract the project name from the argument or phrase. Normalise: lowercase, strip the word "project".
- Keep only pages where either condition holds:
- The page
idstarts withprojects/<name>/(path-based match) - The page's
tagsarray contains<name>(tag-based match)
- The page
- Drop any edge where either endpoint was excluded.
- Note the filter in the summary:
(filtered: project:<name> — X of Y pages) - Set
graph.graph.filter = "project:<name>"in the JSON output.
If both a project filter and a visibility filter are active, apply both (project filter first, then visibility filter on the remaining set).
Visibility Filter (optional)
By default, all pages are exported regardless of visibility tags. This preserves existing behavior.
If the user requests a filtered export — phrases like "public export", "user-facing export", "exclude internal", "no internal pages" — activate visibility filtered mode:
- Build a blocked tag set:
{visibility/internal, visibility/pii} - Skip any page whose frontmatter tags contain a blocked tag when building the node list
- Skip any edge where either endpoint was excluded
- Note the filter in the summary:
(filtered: visibility/internal, visibility/pii excluded)
Pages with no visibility/ tag, or tagged visibility/public, are always included.
Step 1: Build the Node and Edge Lists
Glob all .md files in the vault (excluding _archives/, _raw/, _readouts/, .obsidian/, index.md, log.md, _insights.md). Apply any active filters (project and/or visibility) after collecting the full file list.
For each page, extract from frontmatter:
id— relative path from vault root, without.mdextension (e.g.concepts/transformers)label—titlefield from frontmatter, or filename if missingcategory— directory prefix (concepts,entities,skills,references,synthesis,projects, orjournal)tags— array from frontmatter tags fieldsummary— frontmattersummaryfield if present
This is your node list.
For each page, Grep the body for \[\[.*?\]\] to extract all wikilinks:
- Parse each
[[target]]or[[target|display]]— use the target part only - Resolve the target to a node id (normalize: lowercase, spaces→hyphens, strip
.md) - Skip links that point outside the node list (broken links)
- Each resolved link becomes an edge:
{source: page_id, target: linked_id, relation: "wikilink", confidence: "EXTRACTED"} - If the linking sentence ends with
^[inferred]or^[ambiguous], overrideconfidenceaccordingly
Typed edge enrichment: After building the wikilink edge list, read each page's relationships: frontmatter block. For each {target, type} entry:
- The
targetYAML value is a quoted wikilink string such as"[[concepts/lstm]]". Strip the surrounding[[and]]characters, then apply the same normalization (lowercase, spaces→hyphens, strip.md) to get the node id. - Skip entries whose resolved target is not in the node list (broken link)
- If an edge for this
(source, target)pair already exists, override itsrelationfield with the typed value (e.g.,"contradicts") and settyped: true - If no edge exists yet for this pair, add one:
{source: page_id, target: target_id, relation: <type>, confidence: "EXTRACTED", typed: true}
This means relation: "wikilink" is the default for plain untyped links; a relationships: entry promotes it to a named semantic type. Edges that originated from both a body wikilink and a relationships: entry keep a single record — the typed version wins.
This is your edge list.
Step 2: Assign Community IDs
Group pages into communities by tag clustering:
- Pages sharing the same dominant tag belong to the same community
- Dominant tag = the first tag in the page's frontmatter tags array
- Pages with no tags get community id
null - Number communities starting from 0, ordered by size descending (largest community = 0)
This enables community-based coloring in the HTML visualization and tools like Gephi.
Step 3: Write the Output Files
Create wiki-export/ at the vault root if it doesn't exist. Write all five files:
3a. graph.json
NetworkX node_link format — standard for graph tools and scripts:
{
"directed": false,
"multigraph": false,
"graph": {
"exported_at": "<ISO timestamp>",
"vault": "<OBSIDIAN_VAULT_PATH>",
"total_nodes": N,
"total_edges": M
},
"nodes": [
{
"id": "concepts/transformers",
"label": "Transformer Architecture",
"category": "concepts",
"tags": ["ml", "architecture"],
"summary": "The attention-based architecture introduced in Attention Is All You Need.",
"community": 0
}
],
"links": [
{
"source": "concepts/transformers",
"target": "entities/vaswani",
"relation": "wikilink",
"confidence": "EXTRACTED"
},
{
"source": "concepts/transformers",
"target": "concepts/lstm",
"relation": "contradicts",
"confidence": "EXTRACTED",
"typed": true
}
]
}
3b. graph.graphml
GraphML XML format — loadable in Gephi, yEd, and Cytoscape:
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/graphml">
<key id="label" for="node" attr.name="label" attr.type="string"/>
<key id="category" for="node" attr.name="category" attr.type="string"/>
<key id="tags" for="node" attr.name="tags" attr.type="string"/>
<key id="community" for="node" attr.name="community" attr.type="int"/>
<key id="relation" for="edge" attr.name="relation" attr.type="string"/>
<key id="type" for="edge" attr.name="type" attr.type="string"/>
<key id="confidence" for="edge" attr.name="confidence" attr.type="string"/>
<graph id="wiki" edgedefault="undirected">
<node id="concepts/transformers">
<data key="label">Transformer Architecture</data>
<data key="category">concepts</data>
<data key="tags">ml, architecture</data>
<data key="community">0</data>
</node>
<!-- Untyped wikilink — no <data key="type"> element -->
<edge source="concepts/transformers" target="entities/vaswani">
<data key="relation">wikilink</data>
<data key="confidence">EXTRACTED</data>
</edge>
<!-- Typed edge from relationships: block -->
<edge source="concepts/transformers" target="concepts/lstm">
<data key="relation">contradicts</data>
<data key="type">contradicts</data>
<data key="confidence">EXTRACTED</data>
</edge>
</graph>
</graphml>
Write one <node> per page and one <edge> per link. For typed edges (those where typed: true in the edge list), emit both <data key="relation"> with the semantic type value and <data key="type"> with the same value — this keeps relation readable for tools that already consume it while letting type-aware tools filter on the dedicated type key. Untyped wikilinks omit the <data key="type"> element entirely.
3c. cypher.txt
Neo4j Cypher MERGE statements — paste into Neo4j Browser or run with cypher-shell:
// Wiki knowledge graph export — <TIMESTAMP>
// Load with: cypher-shell -u neo4j -p password < cypher.txt
// Nodes
MERGE (n:Page {id: "concepts/transformers"}) SET n.label = "Transformer Architecture", n.category = "concepts", n.tags = ["ml","architecture"], n.community = 0;
MERGE (n:Page {id: "entities/vaswani"}) SET n.label = "Ashish Vaswani", n.category = "entities", n.tags = ["person","ml"], n.community = 0;
MERGE (n:Page {id: "concepts/lstm"}) SET n.label = "LSTM", n.category = "concepts", n.tags = ["ml","rnn"], n.community = 0;
// Relationships
// Untyped wikilinks use [:WIKILINK]
MATCH (a:Page {id: "concepts/transformers"}), (b:Page {id: "entities/vaswani"}) MERGE (a)-[:WIKILINK {relation: "wikilink", confidence: "EXTRACTED"}]->(b);
// Typed edges use the relationship type as the label (UPPERCASE)
MATCH (a:Page {id: "concepts/transformers"}), (b:Page {id: "concepts/lstm"}) MERGE (a)-[:CONTRADICTS {relation: "contradicts", confidence: "EXTRACTED"}]->(b);
Write one MERGE node statement per page, then one MATCH/MERGE relationship statement per edge. For typed edges, use the type value uppercased as the Cypher relationship label (e.g., contradicts → [:CONTRADICTS], derived_from → [:DERIVED_FROM]). Untyped wikilinks always use [:WIKILINK].
3d. postgres.sql
Plain SQL — loadable into any Postgres database (local, Supabase, RDS, Neon, …) with psql -f postgres.sql or a migration runner. Two tables: wiki_pages (nodes) and wiki_edges (links), with ON CONFLICT upserts so re-running the export is safe and idempotent, mirroring the MERGE semantics of cypher.txt.
-- Wiki knowledge graph export — <TIMESTAMP>
-- Load with: psql -d yourdb -f postgres.sql
CREATE TABLE IF NOT EXISTS wiki_pages (
id TEXT PRIMARY KEY,
label TEXT NOT NULL,
category TEXT,
tags JSONB NOT NULL DEFAULT '[]'::jsonb,
summary TEXT,
community INT
);
CREATE TABLE IF NOT EXISTS wiki_edges (
source TEXT NOT NULL REFERENCES wiki_pages(id) ON DELETE CASCADE,
target TEXT NOT NULL REFERENCES wiki_pages(id) ON DELETE CASCADE,
relation TEXT NOT NULL DEFAULT 'wikilink',
confidence TEXT,
typed BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY (source, target, relation)
);
CREATE INDEX IF NOT EXISTS wiki_edges_source_idx ON wiki_edges(source);
CREATE INDEX IF NOT EXISTS wiki_edges_target_idx ON wiki_edges(target);
-- Nodes
INSERT INTO wiki_pages (id, label, category, tags, summary, community)
VALUES ('concepts/transformers', 'Transformer Architecture', 'concepts', '["ml","architecture"]'::jsonb, 'The attention-based architecture introduced in Attention Is All You Need.', 0)
ON CONFLICT (id) DO UPDATE SET
label = EXCLUDED.label, category = EXCLUDED.category, tags = EXCLUDED.tags,
summary = EXCLUDED.summary, community = EXCLUDED.community;
-- Edges
-- Untyped wikilink
INSERT INTO wiki_edges (source, target, relation, confidence, typed)
VALUES ('concepts/transformers', 'entities/vaswani', 'wikilink', 'EXTRACTED', false)
ON CONFLICT (source, target, relation) DO UPDATE SET confidence = EXCLUDED.confidence, typed = EXCLUDED.typed;
-- Typed edge from relationships: block
INSERT INTO wiki_edges (source, target, relation, confidence, typed)
VALUES ('concepts/transformers', 'concepts/lstm', 'contradicts', 'EXTRACTED', true)
ON CONFLICT (source, target, relation) DO UPDATE SET confidence = EXCLUDED.confidence, typed = EXCLUDED.typed;
Write one INSERT ... ON CONFLICT (id) DO UPDATE statement per page (values escaped: single quotes doubled, tags serialized as a JSON array literal cast to jsonb), then one INSERT ... ON CONFLICT (source, target, relation) DO UPDATE per edge. relation stays lowercase here (unlike the uppercased Cypher relationship label) since it's a plain column value, not a schema identifier — this keeps it directly filterable with WHERE relation = 'contradicts' or joinable without case-folding. typed is true only for edges promoted by a relationships: frontmatter entry; plain wikilinks stay false.
Skip pages whose id collides only after the ON CONFLICT clause fires from a prior run — do not attempt to deduplicate synthetic multi-edges (e.g. same source/target with both a wikilink and a typed relation) since the composite primary key (source, target, relation) already keeps them as distinct rows, matching the "typed version wins" merge behavior of graph.json/graph.graphml at the query layer (SELECT * FROM wiki_edges WHERE source=$1 AND target=$2 ORDER BY typed DESC LIMIT 1).
3e. graph.html
A self-contained interactive visualization using the vis.js CDN (no local dependencies). The user opens this file in any browser — no server needed.
Build the HTML file by:
- Generating a JSON array of node objects for vis.js:
{id: "concepts/transformers", label: "Transformer Architecture", color: {background: "#4E79A7"}, size: <degree * 3 + 8>, title: "concepts | #ml #architecture", community: 0}
- Color by community (cycle through:
#4E79A7,#F28E2B,#E15759,#76B7B2,#59A14F,#EDC948,#B07AA1,#FF9DA7,#9C755F,#BAB0AC) - Size by degree (incoming + outgoing link count):
size = degree * 3 + 8, capped at 60 title= tooltip text shown on hover: category, tags, summary (if available)
- Generating a JSON array of edge objects for vis.js:
// Untyped wikilink
{from: "concepts/transformers", to: "entities/vaswani", dashes: false, width: 1, color: {color: "#666", opacity: 0.6}, title: "wikilink"}
// Typed edge
{from: "concepts/transformers", to: "concepts/lstm", dashes: false, width: 2, color: {color: "#E15759", opacity: 0.8}, label: "contradicts", font: {size: 9, color: "#ccc"}, title: "contradicts"}
dashes: truefor INFERRED edgesdashes: [4,8]for AMBIGUOUS edges- Typed edges (
typed: true): setwidth: 2, add alabelfield showing the type, and apply a type-specific color:
| Type | Edge color |
|---|---|
extends |
#59A14F (green) |
implements |
#4E79A7 (blue) |
contradicts |
#E15759 (red) |
derived_from |
#F28E2B (orange) |
uses |
#76B7B2 (teal) |
replaces |
#B07AA1 (purple) |
related_to |
#BAB0AC (grey — same as untyped) |
Untyped wikilink edges keep the existing #666 grey color and no label.
- Writing the full HTML file:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Wiki Knowledge Graph</title>
<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #0f0f1a; color: #e0e0e0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; display: flex; height: 100vh; }
#graph { flex: 1; }
#sidebar { width: 260px; background: #1a1a2e; border-left: 1px solid #2a2a4e; padding: 14px; overflow-y: auto; font-size: 13px; }
#sidebar h3 { color: #aaa; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 10px; }
#info { margin-bottom: 16px; line-height: 1.6; color: #ccc; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
#stats { margin-top: 16px; color: #555; font-size: 11px; }
</style>
</head>
<body>
<div id="graph"></div>
<div id="sidebar">
<h3>Wiki Knowledge Graph</h3>
<div id="info">Click a node to see details.</div>
<h3 style="margin-top:12px">Communities</h3>
<div id="legend"><!-- populated by JS --></div>
<div id="stats"><!-- populated by JS --></div>
</div>
<script>
const NODES_DATA = /* NODES_JSON */;
const EDGES_DATA = /* EDGES_JSON */;
const COMMUNITY_COLORS = ["#4E79A7","#F28E2B","#E15759","#76B7B2","#59A14F","#EDC948","#B07AA1","#FF9DA7","#9C755F","#BAB0AC"];
const nodes = new vis.DataSet(NODES_DATA);
const edges = new vis.DataSet(EDGES_DATA);
const network = new vis.Network(document.getElementById('graph'), {nodes, edges}, {
physics: { solver: 'forceAtlas2Based', forceAtlas2Based: { gravitationalConstant: -60, springLength: 120 }, stabilization: { iterations: 200 } },
interaction: { hover: true, tooltipDelay: 100 },
nodes: { shape: 'dot', borderWidth: 1.5 },
edges: { smooth: { type: 'continuous' }, arrows: { to: { enabled: true, scaleFactor: 0.4 } } }
});
network.once('stabilizationIterationsDone', () => network.setOptions({ physics: { enabled: false } }));
network.on('click', ({nodes: sel}) => {
if (!sel.length) return;
const n = NODES_DATA.find(x => x.id === sel[0]);
if (!n) return;
document.getElementById('info').innerHTML = `<b>${n.label}</b><br>Category: ${n.category||'—'}<br>Tags: ${n.tags||'—'}<br>${n.summary ? '<br>'+n.summary : ''}`;
});
// Build legend
const communities = {};
NODES_DATA.forEach(n => { if (n.community != null) communities[n.community] = (communities[n.community]||0)+1; });
const leg = document.getElementById('legend');
Object.entries(communities).sort((a,b)=>b[1]-a[1]).forEach(([cid, count]) => {
const color = COMMUNITY_COLORS[cid % COMMUNITY_COLORS.length];
leg.innerHTML += `<div class="legend-item"><div class="dot" style="background:${color}"></div>Community ${cid} (${count})</div>`;
});
document.getElementById('stats').textContent = `${NODES_DATA.length} pages · ${EDGES_DATA.length} links`;
</script>
</body>
</html>
Replace /* NODES_JSON */ and /* EDGES_JSON */ with the actual JSON arrays you generated in step 1.
Step 3.5: OKF Bundle Export (optional)
Run this step only when the user asks for OKF / a markdown bundle (phrases like "export to OKF", "OKF bundle", "open knowledge format", "export as markdown bundle"). It is additive — the five graph files above are always produced; this writes an extra full-fidelity markdown bundle.
The five graph files are a lossy projection (graph skeleton only). An OKF bundle is the actual page bodies, so an export→wiki-import round-trip through OKF preserves full content, and the bundle drops straight into MkDocs, Notion, Hugo, GitHub's renderer, or any Open Knowledge Format consumer.
Canonical frontmatter mapping (obsidian-wiki ⇄ OKF)
This table is the single source of truth for the mapping; wiki-import references it for the reverse direction.
| OKF key | ← export from | → import to | Notes |
|---|---|---|---|
type (required) |
category, title-cased |
category (lower-cased) |
concepts→Concept, entities→Entity, skills→Skill, references→Reference, synthesis→Synthesis, projects→Project, journal→Journal. OKF requires type; consumers tolerate any string. |
title |
title |
title |
Verbatim. |
description |
summary |
summary |
Our one-line summary: is exactly OKF's description (used in index.md entries). |
tags |
tags |
tags |
Verbatim list. visibility/* system tags pass through unchanged. |
generated |
updated → generated.at; by is the producer |
updated ← generated.at |
Write generated: { by: obsidian-wiki/<version>, at: <datetime> }, taking <version> from obsidian-wiki --version (plain obsidian-wiki if the CLI isn't installed). OKF §5 requires every timestamp to be a datetime with an explicit offset, so a date-only updated: 2026-04-12 becomes 2026-04-12T00:00:00Z. Replaces v0.1's timestamp, which is no longer written. |
sources |
sources (list of strings) |
sources (list of strings) |
OKF sources is a list of objects with a required resource, so each native string becomes - resource: <string>. Opaque strings like conversation:2026-04-12 are valid: §5.1 allows scope descriptors a consumer can't follow. Emit nothing else per entry, so import recovers the exact strings. |
status |
lifecycle |
— (native lifecycle is preserved) |
draft → draft; reviewed, verified, disputed → stable; archived → deprecated. Omit status when lifecycle is absent (absent means stable in OKF). |
verified |
_meta/trust-ledger.json entry for the page |
— (preserved verbatim) | Only when the page has a ledger entry: verified: { by: human:vault-owner, at: <entry reviewed_at> }. trust-record only writes entries a human approved with --approved, so the human: actor is accurate and gives the page OKF's human-reviewed tier (§5.3). Never derive verified from lifecycle alone. |
resource |
first sources: entry iff it is an http(s):// URL |
— | Optional; omit when no source URL. Most pages describe abstract knowledge and have none. |
| (extensions) | category, created, updated, relationships, lifecycle, lifecycle_changed, tier, base_confidence, … |
preserved verbatim | OKF §4.1 requires consumers to preserve unknown keys. Writing our native keys as OKF extension frontmatter is what makes the round-trip lossless — on import, preserved category/created/updated/lifecycle are preferred over re-deriving from type/generated/status. (updated rides along because generated.at must be a full datetime, so a date-only updated would otherwise come back as midnight UTC.) sources is not an extension any more: it's a spec field (row above). |
Steps
Reuse the node list from Step 1 (with any active project/visibility filters already applied). Write a directory tree under wiki-export/okf/:
One file per in-scope page. For each page, parse its frontmatter, apply the mapping table above to build the OKF frontmatter (required
typefirst, thentitle,description,tags,generated,status,verified,sources, optionalresource, then the preserved extension keys), transform the body links (below), and write towiki-export/okf/<category>/<slug>.md— same relative path the page has in the vault.Body link transform (
[[wikilinks]]→ standard markdown links):[[concepts/transformers]]→[<target title>](<file-relative path>.md), e.g. fromentities/foo.mda link toconcepts/transformersbecomes[Transformer Architecture](../concepts/transformers.md). Link text = the target page'stitle(fall back to the target id if unknown).[[target|display]]→[display](<rel path>.md).- Use file-relative paths (
../concepts/x.md), never/-absolute —/-rooted links break GitHub rendering. (This matches knowledge-catalog's own production agent.) - Compute that relative path from the target file path, not the bare page id: normalize the wikilink target to its page id, append
.md, then computerelpath(<target-file>, <source-file-dir>). Never callrelpath()on the id before adding.md. - This is required for the common "folder note" layout where a page id exists both as a file and as a directory prefix, e.g.
projects/social-twitter.mdplusprojects/social-twitter/.... Fromprojects/social-twitter/concepts/mem0-memory-analysis.md, a link to[[projects/social-twitter]]must export to../../social-twitter.md, not...md. - Resolve link targets with the same normalization used in Step 1 (lowercase, spaces→hyphens, strip
.md). Handle unresolved targets by form, so forward-references survive the round-trip:- Resolves to an in-scope page → relative markdown link to it.
- Path-form target (contains a
/, e.g.[[concepts/attention-mechanism]]) with no page yet, and not excluded by an active filter → still emit the relative markdown link. OKF §11 forbids rejecting a bundle over a broken cross-link, and keeping the link makes the user's forward-references lossless on re-import. (Verified on st3ve: dropping these silently deleted real[[wikilinks]].) - Excluded by an active project/visibility filter → plain text. Do not emit a path pointing into filtered-out content.
- Bare-title target with no match (e.g.
[[tractorex]]when no such page exists in scope) → plain text; there is no reliable path to write.
- Leave existing external
http(s)://links and# Citationssections untouched.
Generate
index.mdfiles (OKF §8 progressive disclosure; these contain no per-entry frontmatter):- Bundle root
wiki-export/okf/index.md— a# Subdirectoriessection listing each category folder:* [<category>](<category>/index.md) - <one-line description of the category>. This is the only index permitted frontmatter: add a single keyokf_version: "0.2"(OKF §8, §12). - One
index.mdper category folder listing its pages:* [<title>](<slug>.md) - <description from the page's summary>.
- Bundle root
Write
log.mdfrom the vault root'slog.md, reshaped to OKF §9, which requires## YYYY-MM-DDdate headings, newest first. Our log is a flat, oldest-first list of- [<timestamp>] VERB key=value …lines, so: start with# Wiki Update Log; group lines by the date part of<timestamp>; emit groups newest first under## <date>; render each line as* **<Verb>**: <rest of line>, with the verb title-cased (INGEST→Ingest). Keep lines that don't match the pattern under the date of the line above them, verbatim after*.wiki-importignoreslog.md, so this costs nothing on the round-trip.Filters. Honor the same project/visibility filters as the graph export — filtered pages are omitted from the bundle and their inbound links degrade to plain text per step 2.
Excluded from the bundle (same as the graph export): _archives/, _raw/, _readouts/, .obsidian/, _insights.md, _meta/*.base, and the vault root index.md (regenerated above).
Step 4: Print Summary
Wiki export complete → wiki-export/
graph.json — N nodes, M edges (NetworkX node_link format)
graph.graphml — N nodes, M edges (Gephi / yEd / Cytoscape)
cypher.txt — N MERGE nodes + M MERGE relationships (Neo4j)
postgres.sql — N upsert rows (wiki_pages) + M upsert rows (wiki_edges) (any Postgres)
graph.html — interactive browser visualization (open in any browser)
Append this line only when the OKF bundle was produced (Step 3.5):
okf/ — OKF v0.2 markdown bundle (N pages, lossless; import via wiki-import)
Append filter notes when active:
(filtered: project:prismor — 19 of 67 pages)
(filtered: X of Y pages excluded — visibility/internal, visibility/pii)
Only include lines for filters that were actually applied.
Notes
- Re-running is safe — all output files (and the
okf/bundle) are overwritten on each run - Broken wikilinks are skipped — only edges to pages that exist in the vault are exported; in the OKF bundle, a wikilink to a missing/filtered page degrades to plain text
- OKF is the lossless format —
graph.jsonreconstructs only stubs on import, while theokf/bundle preserves full page bodies. Use OKF for vault-to-vault transfer and external markdown tools (MkDocs, Notion, GitHub); use the graph files for analysis tools (Gephi, Neo4j) - The
wiki-export/directory should be gitignored if the vault is version-controlled — these are derived artifacts graph.jsonis the primary format — the others are derived from it. If a future tool supports graph queries natively, point it atgraph.json
| 1 | |
| 2 | name wiki-export |
| 3 | description > |
| 4 | Export the Obsidian wiki's knowledge graph to structured formats for use in external tools. |
| 5 | Use this skill when the user says "export wiki", "export graph", "export to JSON", "export to Gephi", |
| 6 | "export to Neo4j", "export to Postgres", "export to SQL", "graphml", "visualize wiki", |
| 7 | "knowledge graph export", "export to OKF", "OKF bundle", "open knowledge format", |
| 8 | "export as markdown bundle", or wants to use their wiki data in another tool. Outputs |
| 9 | graph.json, graph.graphml, cypher.txt (Neo4j), postgres.sql (Postgres), and graph.html |
| 10 | (interactive browser visualization) into a wiki-export/ directory at the vault root, plus an |
| 11 | optional OKF (Open Knowledge Format) markdown bundle under wiki-export/okf/. |
| 12 | |
| 13 | |
| 14 | # Wiki Export — Knowledge Graph Export |
| 15 | |
| 16 | You are exporting the wiki's wikilink graph to structured formats so it can be used in external tools (Gephi, Neo4j, custom scripts, browser visualization). |
| 17 | |
| 18 | ## Before You Start |
| 19 | |
| 20 | **Resolve config** — follow the Config Resolution Protocol in `llm-wiki/SKILL.md` (inline `@name` override → walk up CWD for `.env` → global config → prompt setup). This gives `OBSIDIAN_VAULT_PATH` |
| 21 | Confirm the vault has pages to export — if fewer than 5 pages exist, warn the user and stop |
| 22 | |
| 23 | ## Project Filter (optional) |
| 24 | |
| 25 | If the user's invocation includes a project name — e.g. `/wiki-export prismor`, `"export the prismor project"`, `"export project:security"` — activate **project filter mode**: |
| 26 | |
| 27 | **Extract the project name** from the argument or phrase. Normalise: lowercase, strip the word "project". |
| 28 | Keep only pages where **either** condition holds: |
| 29 | The page `id` starts with `projects/<name>/` (path-based match) |
| 30 | The page's `tags` array contains `<name>` (tag-based match) |
| 31 | Drop any edge where either endpoint was excluded. |
| 32 | Note the filter in the summary: `(filtered: project:<name> — X of Y pages)` |
| 33 | Set `graph.graph.filter = "project:<name>"` in the JSON output. |
| 34 | |
| 35 | If both a project filter and a visibility filter are active, apply both (project filter first, then visibility filter on the remaining set). |
| 36 | |
| 37 | ## Visibility Filter (optional) |
| 38 | |
| 39 | By default, **all pages are exported** regardless of visibility tags. This preserves existing behavior. |
| 40 | |
| 41 | If the user requests a filtered export — phrases like **"public export"**, **"user-facing export"**, **"exclude internal"**, **"no internal pages"** — activate **visibility filtered mode**: |
| 42 | |
| 43 | Build a **blocked tag set**: `{visibility/internal, visibility/pii}` |
| 44 | Skip any page whose frontmatter tags contain a blocked tag when building the node list |
| 45 | Skip any edge where either endpoint was excluded |
| 46 | Note the filter in the summary: `(filtered: visibility/internal, visibility/pii excluded)` |
| 47 | |
| 48 | Pages with no `visibility/` tag, or tagged `visibility/public`, are always included. |
| 49 | |
| 50 | ## Step 1: Build the Node and Edge Lists |
| 51 | |
| 52 | Glob all `.md` files in the vault (excluding `_archives/`, `_raw/`, `_readouts/`, `.obsidian/`, `index.md`, `log.md`, `_insights.md`). Apply any active filters (project and/or visibility) after collecting the full file list. |
| 53 | |
| 54 | For each page, extract from frontmatter: |
| 55 | `id` — relative path from vault root, without `.md` extension (e.g. `concepts/transformers`) |
| 56 | `label` — `title` field from frontmatter, or filename if missing |
| 57 | `category` — directory prefix (`concepts`, `entities`, `skills`, `references`, `synthesis`, `projects`, or `journal`) |
| 58 | `tags` — array from frontmatter tags field |
| 59 | `summary` — frontmatter `summary` field if present |
| 60 | |
| 61 | This is your **node list**. |
| 62 | |
| 63 | For each page, Grep the body for `\[\[.*?\]\]` to extract all wikilinks: |
| 64 | Parse each `[[target]]` or `[[target|display]]` — use the target part only |
| 65 | Resolve the target to a node id (normalize: lowercase, spaces→hyphens, strip `.md`) |
| 66 | Skip links that point outside the node list (broken links) |
| 67 | Each resolved link becomes an edge: `{source: page_id, target: linked_id, relation: "wikilink", confidence: "EXTRACTED"}` |
| 68 | If the linking sentence ends with `^[inferred]` or `^[ambiguous]`, override `confidence` accordingly |
| 69 | |
| 70 | **Typed edge enrichment:** After building the wikilink edge list, read each page's `relationships:` frontmatter block. For each `{target, type}` entry: |
| 71 | The `target` YAML value is a quoted wikilink string such as `"[[concepts/lstm]]"`. Strip the surrounding `[[` and `]]` characters, then apply the same normalization (lowercase, spaces→hyphens, strip `.md`) to get the node id. |
| 72 | Skip entries whose resolved target is not in the node list (broken link) |
| 73 | If an edge for this `(source, target)` pair already exists, override its `relation` field with the typed value (e.g., `"contradicts"`) and set `typed: true` |
| 74 | If no edge exists yet for this pair, add one: `{source: page_id, target: target_id, relation: <type>, confidence: "EXTRACTED", typed: true}` |
| 75 | |
| 76 | This means `relation: "wikilink"` is the default for plain untyped links; a `relationships:` entry promotes it to a named semantic type. Edges that originated from both a body wikilink and a `relationships:` entry keep a single record — the typed version wins. |
| 77 | |
| 78 | This is your **edge list**. |
| 79 | |
| 80 | ## Step 2: Assign Community IDs |
| 81 | |
| 82 | Group pages into communities by tag clustering: |
| 83 | Pages sharing the same dominant tag belong to the same community |
| 84 | Dominant tag = the first tag in the page's frontmatter tags array |
| 85 | Pages with no tags get community id `null` |
| 86 | Number communities starting from 0, ordered by size descending (largest community = 0) |
| 87 | |
| 88 | This enables community-based coloring in the HTML visualization and tools like Gephi. |
| 89 | |
| 90 | ## Step 3: Write the Output Files |
| 91 | |
| 92 | Create `wiki-export/` at the vault root if it doesn't exist. Write all five files: |
| 93 | |
| 94 | |
| 95 | |
| 96 | ### 3a. `graph.json` |
| 97 | |
| 98 | NetworkX node_link format — standard for graph tools and scripts: |
| 99 | |
| 100 | |
| 101 | { |
| 102 | "directed": false, |
| 103 | "multigraph": false, |
| 104 | "graph": { |
| 105 | "exported_at": "<ISO timestamp>", |
| 106 | "vault": "<OBSIDIAN_VAULT_PATH>", |
| 107 | "total_nodes": N, |
| 108 | "total_edges": M |
| 109 | }, |
| 110 | "nodes": [ |
| 111 | { |
| 112 | "id": "concepts/transformers", |
| 113 | "label": "Transformer Architecture", |
| 114 | "category": "concepts", |
| 115 | "tags": ["ml", "architecture"], |
| 116 | "summary": "The attention-based architecture introduced in Attention Is All You Need.", |
| 117 | "community": 0 |
| 118 | } |
| 119 | ], |
| 120 | "links": [ |
| 121 | { |
| 122 | "source": "concepts/transformers", |
| 123 | "target": "entities/vaswani", |
| 124 | "relation": "wikilink", |
| 125 | "confidence": "EXTRACTED" |
| 126 | }, |
| 127 | { |
| 128 | "source": "concepts/transformers", |
| 129 | "target": "concepts/lstm", |
| 130 | "relation": "contradicts", |
| 131 | "confidence": "EXTRACTED", |
| 132 | "typed": true |
| 133 | } |
| 134 | ] |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | ### 3b. `graph.graphml` |
| 141 | |
| 142 | GraphML XML format — loadable in Gephi, yEd, and Cytoscape: |
| 143 | |
| 144 | |
| 145 | <?xml version="1.0" encoding="UTF-8"?> |
| 146 | <graphml xmlns="http://graphml.graphdrawing.org/graphml"> |
| 147 | <key id="label" for="node" attr.name="label" attr.type="string"/> |
| 148 | <key id="category" for="node" attr.name="category" attr.type="string"/> |
| 149 | <key id="tags" for="node" attr.name="tags" attr.type="string"/> |
| 150 | <key id="community" for="node" attr.name="community" attr.type="int"/> |
| 151 | <key id="relation" for="edge" attr.name="relation" attr.type="string"/> |
| 152 | <key id="type" for="edge" attr.name="type" attr.type="string"/> |
| 153 | <key id="confidence" for="edge" attr.name="confidence" attr.type="string"/> |
| 154 | <graph id="wiki" edgedefault="undirected"> |
| 155 | <node id="concepts/transformers"> |
| 156 | <data key="label">Transformer Architecture</data> |
| 157 | <data key="category">concepts</data> |
| 158 | <data key="tags">ml, architecture</data> |
| 159 | <data key="community">0</data> |
| 160 | </node> |
| 161 | <!-- Untyped wikilink — no <data key="type"> element --> |
| 162 | <edge source="concepts/transformers" target="entities/vaswani"> |
| 163 | <data key="relation">wikilink</data> |
| 164 | <data key="confidence">EXTRACTED</data> |
| 165 | </edge> |
| 166 | <!-- Typed edge from relationships: block --> |
| 167 | <edge source="concepts/transformers" target="concepts/lstm"> |
| 168 | <data key="relation">contradicts</data> |
| 169 | <data key="type">contradicts</data> |
| 170 | <data key="confidence">EXTRACTED</data> |
| 171 | </edge> |
| 172 | </graph> |
| 173 | </graphml> |
| 174 | |
| 175 | |
| 176 | Write one `<node>` per page and one `<edge>` per link. For typed edges (those where `typed: true` in the edge list), emit both `<data key="relation">` with the semantic type value **and** `<data key="type">` with the same value — this keeps `relation` readable for tools that already consume it while letting type-aware tools filter on the dedicated `type` key. Untyped wikilinks omit the `<data key="type">` element entirely. |
| 177 | |
| 178 | |
| 179 | |
| 180 | ### 3c. `cypher.txt` |
| 181 | |
| 182 | Neo4j Cypher `MERGE` statements — paste into Neo4j Browser or run with `cypher-shell`: |
| 183 | |
| 184 | |
| 185 | // Wiki knowledge graph export — <TIMESTAMP> |
| 186 | // Load with: cypher-shell -u neo4j -p password < cypher.txt |
| 187 | |
| 188 | // Nodes |
| 189 | MERGE (n:Page {id: "concepts/transformers"}) SET n.label = "Transformer Architecture", n.category = "concepts", n.tags = ["ml","architecture"], n.community = 0; |
| 190 | MERGE (n:Page {id: "entities/vaswani"}) SET n.label = "Ashish Vaswani", n.category = "entities", n.tags = ["person","ml"], n.community = 0; |
| 191 | MERGE (n:Page {id: "concepts/lstm"}) SET n.label = "LSTM", n.category = "concepts", n.tags = ["ml","rnn"], n.community = 0; |
| 192 | |
| 193 | // Relationships |
| 194 | // Untyped wikilinks use [:WIKILINK] |
| 195 | MATCH (a:Page {id: "concepts/transformers"}), (b:Page {id: "entities/vaswani"}) MERGE (a)-[:WIKILINK {relation: "wikilink", confidence: "EXTRACTED"}]->(b); |
| 196 | // Typed edges use the relationship type as the label (UPPERCASE) |
| 197 | MATCH (a:Page {id: "concepts/transformers"}), (b:Page {id: "concepts/lstm"}) MERGE (a)-[:CONTRADICTS {relation: "contradicts", confidence: "EXTRACTED"}]->(b); |
| 198 | |
| 199 | |
| 200 | Write one `MERGE` node statement per page, then one `MATCH`/`MERGE` relationship statement per edge. For typed edges, use the `type` value uppercased as the Cypher relationship label (e.g., `contradicts` → `[:CONTRADICTS]`, `derived_from` → `[:DERIVED_FROM]`). Untyped wikilinks always use `[:WIKILINK]`. |
| 201 | |
| 202 | |
| 203 | |
| 204 | ### 3d. `postgres.sql` |
| 205 | |
| 206 | Plain SQL — loadable into any Postgres database (local, Supabase, RDS, Neon, …) with `psql -f postgres.sql` or a migration runner. Two tables: `wiki_pages` (nodes) and `wiki_edges` (links), with `ON CONFLICT` upserts so re-running the export is safe and idempotent, mirroring the `MERGE` semantics of `cypher.txt`. |
| 207 | |
| 208 | |
| 209 | -- Wiki knowledge graph export — <TIMESTAMP> |
| 210 | -- Load with: psql -d yourdb -f postgres.sql |
| 211 | |
| 212 | CREATE TABLE IF NOT EXISTS wiki_pages ( |
| 213 | id TEXT PRIMARY KEY, |
| 214 | label TEXT NOT NULL, |
| 215 | category TEXT, |
| 216 | tags JSONB NOT NULL DEFAULT '[]'::jsonb, |
| 217 | summary TEXT, |
| 218 | community INT |
| 219 | ); |
| 220 | |
| 221 | CREATE TABLE IF NOT EXISTS wiki_edges ( |
| 222 | source TEXT NOT NULL REFERENCES wiki_pages(id) ON DELETE CASCADE, |
| 223 | target TEXT NOT NULL REFERENCES wiki_pages(id) ON DELETE CASCADE, |
| 224 | relation TEXT NOT NULL DEFAULT 'wikilink', |
| 225 | confidence TEXT, |
| 226 | typed BOOLEAN NOT NULL DEFAULT false, |
| 227 | PRIMARY KEY (source, target, relation) |
| 228 | ); |
| 229 | |
| 230 | CREATE INDEX IF NOT EXISTS wiki_edges_source_idx ON wiki_edges(source); |
| 231 | CREATE INDEX IF NOT EXISTS wiki_edges_target_idx ON wiki_edges(target); |
| 232 | |
| 233 | -- Nodes |
| 234 | INSERT INTO wiki_pages (id, label, category, tags, summary, community) |
| 235 | VALUES ('concepts/transformers', 'Transformer Architecture', 'concepts', '["ml","architecture"]'::jsonb, 'The attention-based architecture introduced in Attention Is All You Need.', 0) |
| 236 | ON CONFLICT (id) DO UPDATE SET |
| 237 | label = EXCLUDED.label, category = EXCLUDED.category, tags = EXCLUDED.tags, |
| 238 | summary = EXCLUDED.summary, community = EXCLUDED.community; |
| 239 | |
| 240 | -- Edges |
| 241 | -- Untyped wikilink |
| 242 | INSERT INTO wiki_edges (source, target, relation, confidence, typed) |
| 243 | VALUES ('concepts/transformers', 'entities/vaswani', 'wikilink', 'EXTRACTED', false) |
| 244 | ON CONFLICT (source, target, relation) DO UPDATE SET confidence = EXCLUDED.confidence, typed = EXCLUDED.typed; |
| 245 | |
| 246 | -- Typed edge from relationships: block |
| 247 | INSERT INTO wiki_edges (source, target, relation, confidence, typed) |
| 248 | VALUES ('concepts/transformers', 'concepts/lstm', 'contradicts', 'EXTRACTED', true) |
| 249 | ON CONFLICT (source, target, relation) DO UPDATE SET confidence = EXCLUDED.confidence, typed = EXCLUDED.typed; |
| 250 | |
| 251 | |
| 252 | Write one `INSERT ... ON CONFLICT (id) DO UPDATE` statement per page (values escaped: single quotes doubled, `tags` serialized as a JSON array literal cast to `jsonb`), then one `INSERT ... ON CONFLICT (source, target, relation) DO UPDATE` per edge. `relation` stays lowercase here (unlike the uppercased Cypher relationship label) since it's a plain column value, not a schema identifier — this keeps it directly filterable with `WHERE relation = 'contradicts'` or joinable without case-folding. `typed` is `true` only for edges promoted by a `relationships:` frontmatter entry; plain wikilinks stay `false`. |
| 253 | |
| 254 | Skip pages whose `id` collides only after the `ON CONFLICT` clause fires from a prior run — do not attempt to deduplicate synthetic multi-edges (e.g. same source/target with both a `wikilink` and a typed relation) since the composite primary key `(source, target, relation)` already keeps them as distinct rows, matching the "typed version wins" merge behavior of `graph.json`/`graph.graphml` at the query layer (`SELECT * FROM wiki_edges WHERE source=$1 AND target=$2 ORDER BY typed DESC LIMIT 1`). |
| 255 | |
| 256 | |
| 257 | |
| 258 | ### 3e. `graph.html` |
| 259 | |
| 260 | A self-contained interactive visualization using the vis.js CDN (no local dependencies). The user opens this file in any browser — no server needed. |
| 261 | |
| 262 | Build the HTML file by: |
| 263 | |
| 264 | Generating a JSON array of node objects for vis.js: |
| 265 | |
| 266 | {id: "concepts/transformers", label: "Transformer Architecture", color: {background: "#4E79A7"}, size: <degree * 3 + 8>, title: "concepts | #ml #architecture", community: 0} |
| 267 | |
| 268 | Color by community (cycle through: `#4E79A7`, `#F28E2B`, `#E15759`, `#76B7B2`, `#59A14F`, `#EDC948`, `#B07AA1`, `#FF9DA7`, `#9C755F`, `#BAB0AC`) |
| 269 | Size by degree (incoming + outgoing link count): `size = degree * 3 + 8`, capped at 60 |
| 270 | `title` = tooltip text shown on hover: category, tags, summary (if available) |
| 271 | |
| 272 | Generating a JSON array of edge objects for vis.js: |
| 273 | |
| 274 | // Untyped wikilink |
| 275 | {from: "concepts/transformers", to: "entities/vaswani", dashes: false, width: 1, color: {color: "#666", opacity: 0.6}, title: "wikilink"} |
| 276 | // Typed edge |
| 277 | {from: "concepts/transformers", to: "concepts/lstm", dashes: false, width: 2, color: {color: "#E15759", opacity: 0.8}, label: "contradicts", font: {size: 9, color: "#ccc"}, title: "contradicts"} |
| 278 | |
| 279 | `dashes: true` for INFERRED edges |
| 280 | `dashes: [4,8]` for AMBIGUOUS edges |
| 281 | **Typed edges** (`typed: true`): set `width: 2`, add a `label` field showing the type, and apply a type-specific color: |
| 282 | |
| 283 | | Type | Edge color | |
| 284 | |---|---| |
| 285 | | `extends` | `#59A14F` (green) | |
| 286 | | `implements` | `#4E79A7` (blue) | |
| 287 | | `contradicts` | `#E15759` (red) | |
| 288 | | `derived_from` | `#F28E2B` (orange) | |
| 289 | | `uses` | `#76B7B2` (teal) | |
| 290 | | `replaces` | `#B07AA1` (purple) | |
| 291 | | `related_to` | `#BAB0AC` (grey — same as untyped) | |
| 292 | |
| 293 | Untyped `wikilink` edges keep the existing `#666` grey color and no label. |
| 294 | |
| 295 | Writing the full HTML file: |
| 296 | |
| 297 | |
| 298 | <!DOCTYPE html> |
| 299 | <html> |
| 300 | <head> |
| 301 | <meta charset="utf-8"> |
| 302 | <title>Wiki Knowledge Graph</title> |
| 303 | <script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script> |
| 304 | <style> |
| 305 | * { box-sizing: border-box; margin: 0; padding: 0; } |
| 306 | body { background: #0f0f1a; color: #e0e0e0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; display: flex; height: 100vh; } |
| 307 | #graph { flex: 1; } |
| 308 | #sidebar { width: 260px; background: #1a1a2e; border-left: 1px solid #2a2a4e; padding: 14px; overflow-y: auto; font-size: 13px; } |
| 309 | #sidebar h3 { color: #aaa; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 10px; } |
| 310 | #info { margin-bottom: 16px; line-height: 1.6; color: #ccc; } |
| 311 | .legend-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; } |
| 312 | .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; } |
| 313 | #stats { margin-top: 16px; color: #555; font-size: 11px; } |
| 314 | </style> |
| 315 | </head> |
| 316 | <body> |
| 317 | <div id="graph"></div> |
| 318 | <div id="sidebar"> |
| 319 | <h3>Wiki Knowledge Graph</h3> |
| 320 | <div id="info">Click a node to see details.</div> |
| 321 | <h3 style="margin-top:12px">Communities</h3> |
| 322 | <div id="legend"><!-- populated by JS --></div> |
| 323 | <div id="stats"><!-- populated by JS --></div> |
| 324 | </div> |
| 325 | <script> |
| 326 | const NODES_DATA = /* NODES_JSON */; |
| 327 | const EDGES_DATA = /* EDGES_JSON */; |
| 328 | const COMMUNITY_COLORS = ["#4E79A7","#F28E2B","#E15759","#76B7B2","#59A14F","#EDC948","#B07AA1","#FF9DA7","#9C755F","#BAB0AC"]; |
| 329 | |
| 330 | const nodes = new vis.DataSet(NODES_DATA); |
| 331 | const edges = new vis.DataSet(EDGES_DATA); |
| 332 | const network = new vis.Network(document.getElementById('graph'), {nodes, edges}, { |
| 333 | physics: { solver: 'forceAtlas2Based', forceAtlas2Based: { gravitationalConstant: -60, springLength: 120 }, stabilization: { iterations: 200 } }, |
| 334 | interaction: { hover: true, tooltipDelay: 100 }, |
| 335 | nodes: { shape: 'dot', borderWidth: 1.5 }, |
| 336 | edges: { smooth: { type: 'continuous' }, arrows: { to: { enabled: true, scaleFactor: 0.4 } } } |
| 337 | }); |
| 338 | network.once('stabilizationIterationsDone', () => network.setOptions({ physics: { enabled: false } })); |
| 339 | |
| 340 | network.on('click', ({nodes: sel}) => { |
| 341 | if (!sel.length) return; |
| 342 | const n = NODES_DATA.find(x => x.id === sel[0]); |
| 343 | if (!n) return; |
| 344 | document.getElementById('info').innerHTML = `<b>${n.label}</b><br>Category: ${n.category||'—'}<br>Tags: ${n.tags||'—'}<br>${n.summary ? '<br>'+n.summary : ''}`; |
| 345 | }); |
| 346 | |
| 347 | // Build legend |
| 348 | const communities = {}; |
| 349 | NODES_DATA.forEach(n => { if (n.community != null) communities[n.community] = (communities[n.community]||0)+1; }); |
| 350 | const leg = document.getElementById('legend'); |
| 351 | Object.entries(communities).sort((a,b)=>b[1]-a[1]).forEach(([cid, count]) => { |
| 352 | const color = COMMUNITY_COLORS[cid % COMMUNITY_COLORS.length]; |
| 353 | leg.innerHTML += `<div class="legend-item"><div class="dot" style="background:${color}"></div>Community ${cid} (${count})</div>`; |
| 354 | }); |
| 355 | document.getElementById('stats').textContent = `${NODES_DATA.length} pages · ${EDGES_DATA.length} links`; |
| 356 | </script> |
| 357 | </body> |
| 358 | </html> |
| 359 | |
| 360 | |
| 361 | Replace `/* NODES_JSON */` and `/* EDGES_JSON */` with the actual JSON arrays you generated in step 1. |
| 362 | |
| 363 | |
| 364 | |
| 365 | ## Step 3.5: OKF Bundle Export (optional) |
| 366 | |
| 367 | Run this step **only** when the user asks for OKF / a markdown bundle (phrases like "export to OKF", "OKF bundle", "open knowledge format", "export as markdown bundle"). It is additive — the five graph files above are always produced; this writes an extra full-fidelity markdown bundle. |
| 368 | |
| 369 | The five graph files are a *lossy* projection (graph skeleton only). An **OKF bundle is the actual page bodies**, so an export→`wiki-import` round-trip through OKF preserves full content, and the bundle drops straight into MkDocs, Notion, Hugo, GitHub's renderer, or any [Open Knowledge Format] consumer. |
| 370 | |
| 371 | ### Canonical frontmatter mapping (obsidian-wiki ⇄ OKF) |
| 372 | |
| 373 | This table is the single source of truth for the mapping; `wiki-import` references it for the reverse direction. |
| 374 | |
| 375 | | OKF key | ← export from | → import to | Notes | |
| 376 | |---------------|-------------------------|--------------------------|-------| |
| 377 | | `type` (required) | `category`, title-cased | `category` (lower-cased) | `concepts`→`Concept`, `entities`→`Entity`, `skills`→`Skill`, `references`→`Reference`, `synthesis`→`Synthesis`, `projects`→`Project`, `journal`→`Journal`. OKF requires `type`; consumers tolerate any string. | |
| 378 | | `title` | `title` | `title` | Verbatim. | |
| 379 | | `description` | `summary` | `summary` | Our one-line `summary:` is exactly OKF's `description` (used in `index.md` entries). | |
| 380 | | `tags` | `tags` | `tags` | Verbatim list. `visibility/*` system tags pass through unchanged. | |
| 381 | | `generated` | `updated` → `generated.at`; `by` is the producer | `updated` ← `generated.at` | Write `generated: { by: obsidian-wiki/<version>, at: <datetime> }`, taking `<version>` from `obsidian-wiki --version` (plain `obsidian-wiki` if the CLI isn't installed). OKF §5 requires every timestamp to be a datetime with an explicit offset, so a date-only `updated: 2026-04-12` becomes `2026-04-12T00:00:00Z`. Replaces v0.1's `timestamp`, which is no longer written. | |
| 382 | | `sources` | `sources` (list of strings) | `sources` (list of strings) | OKF `sources` is a list of objects with a required `resource`, so each native string becomes `- resource: <string>`. Opaque strings like `conversation:2026-04-12` are valid: §5.1 allows scope descriptors a consumer can't follow. Emit nothing else per entry, so import recovers the exact strings. | |
| 383 | | `status` | `lifecycle` | — (native `lifecycle` is preserved) | `draft` → `draft`; `reviewed`, `verified`, `disputed` → `stable`; `archived` → `deprecated`. Omit `status` when `lifecycle` is absent (absent means `stable` in OKF). | |
| 384 | | `verified` | `_meta/trust-ledger.json` entry for the page | — (preserved verbatim) | Only when the page has a ledger entry: `verified: { by: human:vault-owner, at: <entry reviewed_at> }`. `trust-record` only writes entries a human approved with `--approved`, so the `human:` actor is accurate and gives the page OKF's *human-reviewed* tier (§5.3). Never derive `verified` from `lifecycle` alone. | |
| 385 | | `resource` | first `sources:` entry **iff** it is an `http(s)://` URL | — | Optional; omit when no source URL. Most pages describe abstract knowledge and have none. | |
| 386 | | *(extensions)* | `category`, `created`, `updated`, `relationships`, `lifecycle`, `lifecycle_changed`, `tier`, `base_confidence`, … | preserved verbatim | OKF §4.1 requires consumers to preserve unknown keys. **Writing our native keys as OKF extension frontmatter is what makes the round-trip lossless** — on import, preserved `category`/`created`/`updated`/`lifecycle` are preferred over re-deriving from `type`/`generated`/`status`. (`updated` rides along because `generated.at` must be a full datetime, so a date-only `updated` would otherwise come back as midnight UTC.) `sources` is *not* an extension any more: it's a spec field (row above). | |
| 387 | |
| 388 | ### Steps |
| 389 | |
| 390 | Reuse the node list from Step 1 (with any active project/visibility filters already applied). Write a directory tree under `wiki-export/okf/`: |
| 391 | |
| 392 | **One file per in-scope page.** For each page, parse its frontmatter, apply the mapping table above to build the OKF frontmatter (required `type` first, then `title`, `description`, `tags`, `generated`, `status`, `verified`, `sources`, optional `resource`, then the preserved extension keys), transform the body links (below), and write to `wiki-export/okf/<category>/<slug>.md` — same relative path the page has in the vault. |
| 393 | |
| 394 | **Body link transform** (`[[wikilinks]]` → standard markdown links): |
| 395 | `[[concepts/transformers]]` → `[<target title>]`, e.g. from `entities/foo.md` a link to `concepts/transformers` becomes `[Transformer Architecture]`. Link text = the target page's `title` (fall back to the target id if unknown). |
| 396 | `[[target|display]]` → `[display]`. |
| 397 | Use **file-relative** paths (`../concepts/x.md`), **never** `/`-absolute — `/`-rooted links break GitHub rendering. (This matches knowledge-catalog's own production agent.) |
| 398 | Compute that relative path from the **target file path**, not the bare page id: normalize the wikilink target to its page id, append `.md`, then compute `relpath(<target-file>, <source-file-dir>)`. Never call `relpath()` on the id before adding `.md`. |
| 399 | This is required for the common "folder note" layout where a page id exists both as a file and as a directory prefix, e.g. `projects/social-twitter.md` plus `projects/social-twitter/...`. From `projects/social-twitter/concepts/mem0-memory-analysis.md`, a link to `[[projects/social-twitter]]` must export to `../../social-twitter.md`, not `...md`. |
| 400 | Resolve link targets with the same normalization used in Step 1 (lowercase, spaces→hyphens, strip `.md`). Handle unresolved targets by form, so forward-references survive the round-trip: |
| 401 | **Resolves to an in-scope page** → relative markdown link to it. |
| 402 | **Path-form target** (contains a `/`, e.g. `[[concepts/attention-mechanism]]`) with **no page yet**, and not excluded by an active filter → still emit the relative markdown link. OKF §11 forbids rejecting a bundle over a broken cross-link, and keeping the link makes the user's forward-references lossless on re-import. (Verified on st3ve: dropping these silently deleted real `[[wikilinks]]`.) |
| 403 | **Excluded by an active project/visibility filter** → plain text. Do not emit a path pointing into filtered-out content. |
| 404 | **Bare-title target** with no match (e.g. `[[tractorex]]` when no such page exists in scope) → plain text; there is no reliable path to write. |
| 405 | Leave existing external `http(s)://` links and `# Citations` sections untouched. |
| 406 | |
| 407 | **Generate `index.md` files** (OKF §8 progressive disclosure; these contain no per-entry frontmatter): |
| 408 | Bundle root `wiki-export/okf/index.md` — a `# Subdirectories` section listing each category folder: `* [<category>] - <one-line description of the category>`. This is the **only** index permitted frontmatter: add a single key `okf_version: "0.2"` (OKF §8, §12). |
| 409 | One `index.md` per category folder listing its pages: `* [<title>] - <description from the page's summary>`. |
| 410 | |
| 411 | **Write `log.md`** from the vault root's `log.md`, reshaped to OKF §9, which requires `## YYYY-MM-DD` date headings, newest first. Our log is a flat, oldest-first list of `- [<timestamp>] VERB key=value …` lines, so: start with `# Wiki Update Log`; group lines by the date part of `<timestamp>`; emit groups newest first under `## <date>`; render each line as `* **<Verb>**: <rest of line>`, with the verb title-cased (`INGEST` → `Ingest`). Keep lines that don't match the pattern under the date of the line above them, verbatim after `* `. `wiki-import` ignores `log.md`, so this costs nothing on the round-trip. |
| 412 | |
| 413 | **Filters.** Honor the same project/visibility filters as the graph export — filtered pages are omitted from the bundle and their inbound links degrade to plain text per step 2. |
| 414 | |
| 415 | Excluded from the bundle (same as the graph export): `_archives/`, `_raw/`, `_readouts/`, `.obsidian/`, `_insights.md`, `_meta/*.base`, and the vault root `index.md` (regenerated above). |
| 416 | |
| 417 | |
| 418 | |
| 419 | ## Step 4: Print Summary |
| 420 | |
| 421 | |
| 422 | Wiki export complete → wiki-export/ |
| 423 | graph.json — N nodes, M edges (NetworkX node_link format) |
| 424 | graph.graphml — N nodes, M edges (Gephi / yEd / Cytoscape) |
| 425 | cypher.txt — N MERGE nodes + M MERGE relationships (Neo4j) |
| 426 | postgres.sql — N upsert rows (wiki_pages) + M upsert rows (wiki_edges) (any Postgres) |
| 427 | graph.html — interactive browser visualization (open in any browser) |
| 428 | |
| 429 | |
| 430 | Append this line only when the OKF bundle was produced (Step 3.5): |
| 431 | |
| 432 | okf/ — OKF v0.2 markdown bundle (N pages, lossless; import via wiki-import) |
| 433 | |
| 434 | |
| 435 | Append filter notes when active: |
| 436 | |
| 437 | (filtered: project:prismor — 19 of 67 pages) |
| 438 | (filtered: X of Y pages excluded — visibility/internal, visibility/pii) |
| 439 | |
| 440 | Only include lines for filters that were actually applied. |
| 441 | |
| 442 | ## Notes |
| 443 | |
| 444 | **Re-running is safe** — all output files (and the `okf/` bundle) are overwritten on each run |
| 445 | **Broken wikilinks are skipped** — only edges to pages that exist in the vault are exported; in the OKF bundle, a wikilink to a missing/filtered page degrades to plain text |
| 446 | **OKF is the lossless format** — `graph.json` reconstructs only stubs on import, while the `okf/` bundle preserves full page bodies. Use OKF for vault-to-vault transfer and external markdown tools (MkDocs, Notion, GitHub); use the graph files for analysis tools (Gephi, Neo4j) |
| 447 | **The `wiki-export/` directory should be gitignored** if the vault is version-controlled — these are derived artifacts |
| 448 | **`graph.json` is the primary format** — the others are derived from it. If a future tool supports graph queries natively, point it at `graph.json` |
| 449 |
Discussion
Alternatives
Browse more free Claude skills or everything in Operations.