Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

docs(spec,plan): agent-facing second-brain layer for the Obsidian plugin

FABIOTESS77c21c902a54
diff --git a/docs/superpowers/plans/2026-08-14-obsidian-plugin.md b/docs/superpowers/plans/2026-08-14-obsidian-plugin.md
index 69b91fab..11d63a2d 100644
--- a/docs/superpowers/plans/2026-08-14-obsidian-plugin.md
+++ b/docs/superpowers/plans/2026-08-14-obsidian-plugin.md
@@ -14,7 +14,10 @@
- Plugin id `open-ontologies`, name "Open Ontologies", `isDesktopOnly: true`, `minAppVersion: "1.5.0"`, initial version `0.1.0`.
- Engine consumed **as released, zero Rust changes**. Pinned `ENGINE_VERSION = "1.1.1"`; compatibility rule `major === 1 && minor >= 1`.
- Engine release facts (verified 2026-08-14): tags are `v`-prefixed (`v1.1.1`); assets are `open-ontologies-aarch64-apple-darwin`, `open-ontologies-x86_64-apple-darwin`, `open-ontologies-x86_64-unknown-linux-gnu`, `open-ontologies-x86_64-pc-windows-msvc.exe`, plus `SHASUMS.txt` (sha256sum format, two-space separator).
-- Sidecar CLI: `open-ontologies serve-http --host 127.0.0.1 --port <p>`. Defaults to 127.0.0.1 already; we pass it explicitly anyway. MCP endpoint `http://127.0.0.1:<p>/mcp`; liveness `GET /health` → `{"status":"ok","version":"1.1.1"}`.
+- Sidecar CLI: `open-ontologies serve-http --host 127.0.0.1 --port <p> --token <t>`. Defaults to 127.0.0.1 already; we pass it explicitly anyway. MCP endpoint `http://127.0.0.1:<p>/mcp`; liveness `GET /health` → `{"status":"ok","version":"1.1.1"}` (outside the bearer layer, so health checks need no token).
+- **Auth is mandatory.** The engine applies `CorsLayer::permissive()` to the router (verified in `src/main.rs`), so a fixed, documented port without a token would be reachable cross-origin from any page in the user's browser. The plugin generates a 32-byte hex token on first run and never spawns the engine without one. No setting disables it.
+- Stable port default **27125** (beside Local REST API's 27124), so an external MCP client can be configured once. Falls back to an ephemeral port with a notice if occupied.
+- MCP client config emitted by settings (verified against current Claude Code docs; same shape for Claude Desktop's `claude_desktop_config.json`): `{"mcpServers":{"open-ontologies":{"type":"http","url":"http://127.0.0.1:27125/mcp","headers":{"Authorization":"Bearer <token>"}}}}`.
- All engine tools return a JSON **string** in `result.content[0].text` of a `tools/call` response. Tool names verified: `onto_validate`, `onto_load`, `onto_query`, `onto_reason`, `onto_reason_incremental`, `onto_classify_el`, `onto_shacl`, `onto_shacl_check`, `onto_diff`, `onto_lint`, `onto_apply`, `onto_save`, `onto_stats`, `onto_pack`, `onto_unpack`.
- Spec deviation (agreed rationale): typed links use the Dataview inline-field convention `property:: [[Target]]` (community standard, machine-parseable) rather than the literal `[[property::Target]]` syntax, which is not a valid Obsidian link.
- No em dashes in any user-facing copy (README, settings text, notices).
@@ -42,6 +45,8 @@ obsidian-open-ontologies/
│ │ ├── rules.ts # MappingRules + YAML parse (pure)
│ │ └── mapper.ts # NoteInput → N-Triples (pure)
│ ├── sparql.ts # tolerant SPARQL-result parsing (pure)
+│ ├── inferred.ts # entailed-minus-asserted diff (pure)
+│ ├── starter/ # bundled vault ontology + SHACL shapes
│ └── views/
│ ├── validation.ts # validation results pane
│ ├── tree.ts # ontology tree pane
@@ -683,7 +688,10 @@ export class EngineClient {
private nextId = 1;
private sessionId?: string;
- constructor(public baseUrl: string) {}
+ constructor(
+ public baseUrl: string,
+ private token?: string,
+ ) {}
async health(): Promise<HealthInfo> {
const res = await fetch(`${this.baseUrl}/health`);
@@ -697,6 +705,7 @@ export class EngineClient {
accept: "application/json, text/event-stream",
};
if (this.sessionId) headers["mcp-session-id"] = this.sessionId;
+ if (this.token) headers["authorization"] = `Bearer ${this.token}`;
const res = await fetch(`${this.baseUrl}/mcp`, { method: "POST", headers, body: JSON.stringify(payload) });
const sid = res.headers.get("mcp-session-id");
if (sid) this.sessionId = sid;
@@ -989,6 +998,8 @@ import { downloadEngine } from "./download";
export interface ManagerOptions {
binDir: string;
explicitPath?: string;
+ preferredPort: number;
+ token: string;
log: (line: string) => void;
}
@@ -996,6 +1007,7 @@ const BACKOFF_MS = [1000, 5000, 15000];
export class EngineManager {
client: EngineClient | null = null;
+ port: number | null = null;
private child: ChildProcess | null = null;
private stopping = false;
private restarts = 0;
@@ -1023,23 +1035,39 @@ export class EngineManager {
return downloadEngine(this.opts.binDir, (s) => this.log(s));
}
- private freePort(): Promise<number> {
- return new Promise((resolve, reject) => {
+ private probePort(candidate: number): Promise<number | null> {
+ return new Promise((resolve) => {
const srv = net.createServer();
- srv.listen(0, "127.0.0.1", () => {
+ srv.once("error", () => resolve(null));
+ srv.listen(candidate, "127.0.0.1", () => {
const port = (srv.address() as net.AddressInfo).port;
srv.close(() => resolve(port));
});
- srv.on("error", reject);
});
}
+ private async resolvePort(): Promise<number> {
+ const preferred = await this.probePort(this.opts.preferredPort);
+ if (preferred !== null) return preferred;
+ this.log(
+ `Port ${this.opts.preferredPort} is in use; falling back to a random port. External MCP clients configured against ${this.opts.preferredPort} will not reach this engine until the port is free.`,
+ );
+ const ephemeral = await this.probePort(0);
+ if (ephemeral === null) throw new Error("Could not bind any loopback port");
+ return ephemeral;
+ }
+
async start(): Promise<EngineClient> {
this.stopping = false;
const binary = await this.resolveBinary();
- const port = await this.freePort();
- this.log(`Starting engine: ${binary} serve-http --host 127.0.0.1 --port ${port}`);
- this.child = spawn(binary, ["serve-http", "--host", "127.0.0.1", "--port", String(port)], { stdio: ["ignore", "ignore", "pipe"] });
+ const port = await this.resolvePort();
+ this.port = port;
+ this.log(`Starting engine: ${binary} serve-http --host 127.0.0.1 --port ${port} --token <redacted>`);
+ this.child = spawn(
+ binary,
+ ["serve-http", "--host", "127.0.0.1", "--port", String(port), "--token", this.opts.token],
+ { stdio: ["ignore", "ignore", "pipe"] },
+ );
this.child.stderr!.on("data", (c: Buffer) => c.toString().split("\n").filter(Boolean).forEach((l) => this.log(l)));
this.child.on("exit", (code) => {
this.client = null;
@@ -1054,7 +1082,7 @@ export class EngineManager {
}
});
- const client = new EngineClient(`http://127.0.0.1:${port}`);
+ const client = new EngineClient(`http://127.0.0.1:${port}`, this.opts.token);
let health = null;
for (let i = 0; i < 30; i++) {
try { health = await client.health(); break; } catch { await new Promise((r) => setTimeout(r, 500)); }
@@ -1177,16 +1205,43 @@ git add src/sparql.ts tests/sparql.test.ts && git commit -m "feat: tolerant SPAR
- [ ] **Step 1: Implement settings.ts**
```ts
-import { App, PluginSettingTab, Setting } from "obsidian";
+import { App, Notice, PluginSettingTab, Setting } from "obsidian";
+import { randomBytes } from "node:crypto";
import type OpenOntologiesPlugin from "./main";
export interface OpenOntologiesSettings {
enginePath: string; // empty = auto-download
mappingYaml: string; // overrides for MappingRules
sparqlHistory: string[];
+ mcpPort: number; // stable port for external MCP clients
+ mcpToken: string; // generated on first run; never empty at runtime
+ autoSync: boolean; // debounced vault -> graph re-sync on markdown change
}
-export const DEFAULT_SETTINGS: OpenOntologiesSettings = { enginePath: "", mappingYaml: "", sparqlHistory: [] };
+export const DEFAULT_SETTINGS: OpenOntologiesSettings = {
+ enginePath: "",
+ mappingYaml: "",
+ sparqlHistory: [],
+ mcpPort: 27125,
+ mcpToken: "",
+ autoSync: true,
+};
+
+export function mcpClientConfig(port: number, token: string): string {
+ return JSON.stringify(
+ {
+ mcpServers: {
+ "open-ontologies": {
+ type: "http",
+ url: `http://127.0.0.1:${port}/mcp`,
+ headers: { Authorization: `Bearer ${token}` },
+ },
+ },
+ },
+ null,
+ 2,
+ );
+}
export class OpenOntologiesSettingTab extends PluginSettingTab {
constructor(app: App, private plugin: OpenOntologiesPlugin) { super(app, plugin); }
@@ -1211,6 +1266,49 @@ export class OpenOntologiesSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));
+ new Setting(containerEl)
+ .setName("Auto-sync vault to graph")
+ .setDesc("Re-compile the vault into the knowledge graph 10 seconds after the last note change, so an MCP client always queries current data.")
+ .addToggle((t) => t.setValue(this.plugin.settings.autoSync).onChange(async (v) => {
+ this.plugin.settings.autoSync = v;
+ await this.plugin.saveSettings();
+ }));
+
+ containerEl.createEl("h3", { text: "Connect an AI agent" });
+ containerEl.createEl("p", {
+ text: "The engine is an MCP server. Point Claude Code or Claude Desktop at it and your agent can query, reason over and validate the vault graph. Access requires the token below, so keep it private.",
+ });
+
+ new Setting(containerEl)
+ .setName("MCP port")
+ .setDesc("Stable loopback port for external MCP clients. Changing it restarts the engine and invalidates any config you already copied.")
+ .addText((t) => t.setValue(String(this.plugin.settings.mcpPort)).onChange(async (v) => {
+ const n = Number(v);
+ if (!Number.isInteger(n) || n < 1024 || n > 65535) return;
+ this.plugin.settings.mcpPort = n;
+ await this.plugin.saveSettings();
+ }));
+
+ new Setting(containerEl)
+ .setName("Copy MCP client config")
+ .setDesc("Copies a ready-to-paste JSON block containing the URL and access token.")
+ .addButton((b) => b.setButtonText("Copy").onClick(async () => {
+ await navigator.clipboard.writeText(
+ mcpClientConfig(this.plugin.settings.mcpPort, this.plugin.settings.mcpToken),
+ );
+ new Notice("MCP client config copied. It contains your access token.");
+ }));
+
+ new Setting(containerEl)
+ .setName("Regenerate access token")
+ .setDesc("Issues a new token and restarts the engine. Any MCP client using the old token stops working until you copy the config again.")
+ .addButton((b) => b.setButtonText("Regenerate").setWarning().onClick(async () => {
+ this.plugin.settings.mcpToken = randomBytes(32).toString("hex");
+ await this.plugin.saveSettings();
+ await this.plugin.restartEngine();
+ this.display();
+ }));
+
new Setting(containerEl)
.setName("Restart engine")
.addButton((b) => b.setButtonText("Restart").onClick(() => this.plugin.restartEngine()));
@@ -1227,6 +1325,7 @@ export class OpenOntologiesSettingTab extends PluginSettingTab {
```ts
import { Notice, Plugin, TFile, FuzzySuggestModal, FileSystemAdapter, normalizePath } from "obsidian";
+import { randomBytes } from "node:crypto";
import { EngineManager } from "./engine/manager";
import { EngineClient } from "./engine/client";
import { DEFAULT_SETTINGS, OpenOntologiesSettings, OpenOntologiesSettingTab } from "./settings";
@@ -1301,12 +1400,35 @@ export default class OpenOntologiesPlugin extends Plugin {
async onload() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
+ if (!this.settings.mcpToken) {
+ this.settings.mcpToken = randomBytes(32).toString("hex");
+ await this.saveSettings();
+ }
const binDir = path.join(this.fullPath(this.app.vault.configDir + "/plugins/open-ontologies"), "bin");
this.manager = new EngineManager({
binDir,
explicitPath: this.settings.enginePath || undefined,
+ preferredPort: this.settings.mcpPort,
+ token: this.settings.mcpToken,
log: (l) => console.log(`[open-ontologies] ${l}`),
});
+
+ // Auto-sync: keep the graph an MCP client queries current.
+ let syncTimer: number | null = null;
+ const scheduleSync = () => {
+ if (!this.settings.autoSync) return;
+ if (syncTimer) window.clearTimeout(syncTimer);
+ syncTimer = window.setTimeout(() => {
+ this.syncVault().catch((e) => console.error("[open-ontologies] auto-sync failed", e));
+ }, 10000);
+ };
+ for (const ev of ["create", "modify", "delete", "rename"] as const) {
+ this.registerEvent(
+ (this.app.vault as any).on(ev, (f: any) => {
+ if (f?.extension === "md") scheduleSync();
+ }),
+ );
+ }
this.addSettingTab(new OpenOntologiesSettingTab(this.app, this));
// Views are registered in Tasks 10-12; commands that depend on them activate the leaves.
@@ -1789,6 +1911,246 @@ git add src/views/console.ts src/main.ts && git commit -m "feat(views): SPARQL c
---
+### Task 12b: Starter vault ontology and shapes
+
+**Files:**
+- Create: `src/starter/vault-ontology.ttl.ts` (Turtle embedded as a TS string constant so esbuild bundles it), `src/starter/vault-shapes.ttl.ts`
+- Modify: `src/main.ts` (command `oo-install-starter-ontology`)
+- Test: `tests/starter.test.ts`
+
+**Why this task exists:** OWL-RL over an untyped vault entails nothing. `vault:linksTo` triples alone support no interesting inference, so without a vocabulary the whole agent-facing story is vacuous. Transitive `partOf` and symmetric `relatesTo` are what give the reasoner derivations to make.
+
+**Interfaces:**
+- Produces: `VAULT_ONTOLOGY_TTL: string`, `VAULT_SHAPES_TTL: string`; command writes them to `<vault>/ontology/vault-ontology.ttl` and `<vault>/ontology/vault-shapes.ttl`, refusing to overwrite existing files.
+
+- [ ] **Step 1: Write the failing test**
+
+```ts
+import { describe, it, expect } from "vitest";
+import { VAULT_ONTOLOGY_TTL, VAULT_SHAPES_TTL } from "../src/starter/vault-ontology.ttl";
+
+describe("starter ontology", () => {
+ it("declares the second-brain vocabulary", () => {
+ for (const cls of ["Note", "Person", "Project", "Task", "Source", "Idea", "Topic"]) {
+ expect(VAULT_ONTOLOGY_TTL).toContain(`vault:${cls}`);
+ }
+ });
+ it("makes partOf transitive and relatesTo symmetric so reasoning has something to derive", () => {
+ expect(VAULT_ONTOLOGY_TTL).toContain("owl:TransitiveProperty");
+ expect(VAULT_ONTOLOGY_TTL).toContain("owl:SymmetricProperty");
+ });
+ it("ships shapes targeting the vocabulary", () => {
+ expect(VAULT_SHAPES_TTL).toContain("sh:NodeShape");
+ expect(VAULT_SHAPES_TTL).toContain("sh:targetClass");
+ });
+});
+```
+
+- [ ] **Step 2: Run to verify it fails** — `npm test -- tests/starter.test.ts` → FAIL (module missing).
+
+- [ ] **Step 3: Implement `src/starter/vault-ontology.ttl.ts`**
+
+```ts
+export const VAULT_ONTOLOGY_TTL = `@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix vault: <vault:> .
+
+vault:Note a owl:Class ; rdfs:label "Note" .
+vault:Person a owl:Class ; rdfs:subClassOf vault:Note ; rdfs:label "Person" .
+vault:Project a owl:Class ; rdfs:subClassOf vault:Note ; rdfs:label "Project" .
+vault:Task a owl:Class ; rdfs:subClassOf vault:Note ; rdfs:label "Task" .
+vault:Source a owl:Class ; rdfs:subClassOf vault:Note ; rdfs:label "Source" .
+vault:Idea a owl:Class ; rdfs:subClassOf vault:Note ; rdfs:label "Idea" .
+vault:Topic a owl:Class ; rdfs:subClassOf vault:Note ; rdfs:label "Topic" .
+
+# Transitive: a Task partOf a Project partOf a Programme is entailed to be partOf the Programme.
+vault:partOf a owl:ObjectProperty, owl:TransitiveProperty ;
+ rdfs:label "part of" ; rdfs:domain vault:Note ; rdfs:range vault:Note .
+
+# Symmetric: relating A to B entails B relates to A, so one-directional notes still connect.
+vault:relatesTo a owl:ObjectProperty, owl:SymmetricProperty ;
+ rdfs:label "relates to" ; rdfs:domain vault:Note ; rdfs:range vault:Note .
+
+vault:authoredBy a owl:ObjectProperty ;
+ rdfs:label "authored by" ; rdfs:domain vault:Note ; rdfs:range vault:Person .
+
+vault:references a owl:ObjectProperty ;
+ rdfs:label "references" ; rdfs:domain vault:Note ; rdfs:range vault:Source .
+
+vault:about a owl:ObjectProperty ;
+ rdfs:label "about" ; rdfs:domain vault:Note ; rdfs:range vault:Topic .
+`;
+
+export const VAULT_SHAPES_TTL = `@prefix sh: <http://www.w3.org/ns/shacl#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+@prefix vault: <vault:> .
+
+vault:TaskShape a sh:NodeShape ;
+ sh:targetClass vault:Task ;
+ sh:property [ sh:path vault:partOf ; sh:minCount 1 ;
+ sh:message "A Task should record which Project it is part of." ] .
+
+vault:SourceShape a sh:NodeShape ;
+ sh:targetClass vault:Source ;
+ sh:property [ sh:path vault:url ; sh:minCount 1 ; sh:datatype xsd:string ;
+ sh:message "A Source should record where it came from." ] .
+`;
+```
+
+- [ ] **Step 4: Run to verify it passes** — `npm test -- tests/starter.test.ts` → PASS.
+
+- [ ] **Step 5: Add the install command to `main.ts` `onload()`**
+
+```ts
+this.addCommand({
+ id: "oo-install-starter-ontology",
+ name: "Install starter vault ontology",
+ callback: async () => {
+ const { VAULT_ONTOLOGY_TTL, VAULT_SHAPES_TTL } = await import("./starter/vault-ontology.ttl");
+ const targets: [string, string][] = [
+ ["ontology/vault-ontology.ttl", VAULT_ONTOLOGY_TTL],
+ ["ontology/vault-shapes.ttl", VAULT_SHAPES_TTL],
+ ];
+ let written = 0;
+ for (const [rel, body] of targets) {
+ if (await this.app.vault.adapter.exists(rel)) continue;
+ const dir = rel.split("/").slice(0, -1).join("/");
+ if (dir && !(await this.app.vault.adapter.exists(dir))) await this.app.vault.adapter.mkdir(dir);
+ await this.app.vault.adapter.write(rel, body);
+ written++;
+ }
+ new Notice(
+ written === 0
+ ? "Starter ontology already present; nothing overwritten."
+ : `Installed ${written} starter file(s) under ontology/. Add 'type: \"[[Project]]\"' style frontmatter to your notes, then sync.`,
+ 10000,
+ );
+ },
+});
+```
+
+- [ ] **Step 6: Build, test, commit**
+
+```bash
+npm run build && npm test
+git add src/starter src/main.ts tests/starter.test.ts
+git commit -m "feat(starter): vault ontology and SHACL shapes so reasoning has something to entail"
+```
+
+---
+
+### Task 12c: Inferred connections
+
+**Files:**
+- Create: `src/inferred.ts`
+- Modify: `src/main.ts` (command `oo-inferred-connections`)
+- Test: `tests/inferred.test.ts`
+
+**Why this task exists:** this is the feature a file-access MCP server cannot offer, and the concrete meaning of "the brain gets smarter". Obsidian shows asserted backlinks; we show entailed ones.
+
+**Interfaces:**
+- Consumes: `EngineClient` (Task 5), `parseBindings` (Task 8), `toValidationItems`/`ValidationItem` (Task 10), `mintNoteIri` (Task 2).
+- Produces: `diffTriples(closure: Triple[], asserted: Triple[]): Triple[]` where `interface Triple { s: string; p: string; o: string }` — set difference keyed on `s|p|o`; `inferredToItems(rows: Triple[]): ValidationItem[]`.
+
+- [ ] **Step 1: Write the failing test**
+
+```ts
+import { describe, it, expect } from "vitest";
+import { diffTriples } from "../src/inferred";
+
+describe("diffTriples", () => {
+ it("returns closure triples that were never asserted", () => {
+ const asserted = [{ s: "vault:A", p: "vault:partOf", o: "vault:B" }];
+ const closure = [
+ { s: "vault:A", p: "vault:partOf", o: "vault:B" },
+ { s: "vault:A", p: "vault:partOf", o: "vault:C" },
+ ];
+ expect(diffTriples(closure, asserted)).toEqual([{ s: "vault:A", p: "vault:partOf", o: "vault:C" }]);
+ });
+ it("returns nothing when the closure adds nothing", () => {
+ const t = [{ s: "vault:A", p: "vault:relatesTo", o: "vault:B" }];
+ expect(diffTriples(t, t)).toEqual([]);
+ });
+});
+```
+
+- [ ] **Step 2: Run to verify it fails** — `npm test -- tests/inferred.test.ts` → FAIL.
+
+- [ ] **Step 3: Implement `src/inferred.ts`**
+
+```ts
+import { ValidationItem } from "./views/validation";
+
+export interface Triple { s: string; p: string; o: string }
+
+const key = (t: Triple) => `${t.s}|${t.p}|${t.o}`;
+
+export function diffTriples(closure: Triple[], asserted: Triple[]): Triple[] {
+ const seen = new Set(asserted.map(key));
+ return closure.filter((t) => !seen.has(key(t)));
+}
+
+function short(iri: string): string {
+ const tail = iri.split(/[/#:]/).pop() ?? iri;
+ try { return decodeURIComponent(tail); } catch { return tail; }
+}
+
+export function inferredToItems(rows: Triple[]): ValidationItem[] {
+ if (!rows.length) {
+ return [{ severity: "info", message: "No inferred connections. Add types and relations to your notes, then reason again." }];
+ }
+ return rows.map((t) => ({
+ severity: "inferred",
+ message: `${short(t.s)} — ${short(t.p)} → ${short(t.o)}`,
+ }));
+}
+```
+
+- [ ] **Step 4: Run to verify it passes** — `npm test -- tests/inferred.test.ts` → PASS.
+
+- [ ] **Step 5: Add the command to `main.ts` `onload()`**
+
+The order matters: capture the asserted state, reason, capture the closure, diff. `onto_clear` + reload of the vault N-Triples restores the asserted-only graph afterwards so a later sync is not confused by materialised triples.
+
+```ts
+this.addCommand({
+ id: "oo-inferred-connections",
+ name: "Show inferred connections for this note",
+ checkCallback: (checking) => {
+ const f = this.app.workspace.getActiveFile();
+ if (!f || f.extension !== "md") return false;
+ if (!checking) {
+ (async () => {
+ const c = await this.client();
+ const rules = this.rules();
+ const subject = `<${mintNoteIri(f.path, rules.iriBase)}>`;
+ const q = `SELECT ?p ?o WHERE { ${subject} ?p ?o . FILTER(isIRI(?o)) }`;
+ const before = parseBindings(await c.call("onto_query", { query: q })) ?? [];
+ await c.call("onto_reason", { profile: "owl-rl" });
+ const after = parseBindings(await c.call("onto_query", { query: q })) ?? [];
+ const toTriple = (r: Record<string, string>): Triple => ({ s: subject, p: r.p, o: r.o });
+ const fresh = diffTriples(after.map(toTriple), before.map(toTriple));
+ await this.showValidation(inferredToItems(fresh));
+ await this.syncVault(); // reload asserted-only state after materialisation
+ })().catch((e) => new Notice(e.message, 8000));
+ }
+ return true;
+ },
+});
+```
+
+Add imports: `import { diffTriples, inferredToItems, Triple } from "./inferred";`, `import { mintNoteIri } from "./mapper/iri";`, `import { parseBindings } from "./sparql";`. Add a `.oo-sev-inferred { border-left-color: var(--text-accent); }` rule to `styles.css`.
+
+- [ ] **Step 6: Build, test, commit**
+
+```bash
+npm run build && npm test
+git add src/inferred.ts src/main.ts src/views/validation.ts styles.css tests/inferred.test.ts
+git commit -m "feat(inferred): surface entailed connections a note never asserted"
+```
+
+---
+
### Task 13: test-vault, e2e test against the real engine, CI
**Files:**
@@ -1983,8 +2345,31 @@ Desktop only. On first run the plugin downloads the pinned engine release for yo
- Ontology tree pane, SPARQL console with history, validation panel with per-note deep links
- Validate-on-save for .ttl, .owl, .rdf and .jsonld files
- Vault to RDF mapping: notes become individuals, `type:` frontmatter becomes `rdf:type`, `property:: [[Target]]` inline fields become object properties, tags become SKOS concepts
+- Inferred connections: see the links your notes entail but never stated
- Every engine tool is reachable; reasoning profiles from RDFS to full OWL 2 DL tableaux
+## Give your AI agent a reasoned second brain
+
+The engine this plugin runs is an MCP server, so Claude Code and Claude Desktop can query your vault as a knowledge graph. This is a different thing from letting an agent read your files. Tools like mcp-obsidian already do file read, write and search well, and this plugin does not duplicate them. What it adds is reasoning: your agent can ask which notes violate a shape, what is transitively part of a project, or which people sit two hops from a topic, and get answers derived from the graph rather than guessed from text.
+
+Open the plugin settings, copy the MCP client config, and paste it into your Claude Code config:
+
+```json
+{
+ "mcpServers": {
+ "open-ontologies": {
+ "type": "http",
+ "url": "http://127.0.0.1:27125/mcp",
+ "headers": { "Authorization": "Bearer YOUR_TOKEN" }
+ }
+ }
+}
+```
+
+The endpoint listens on loopback only and always requires the generated token. Treat that token like a password: anything holding it can read and modify your vault graph.
+
+One honest caveat about how much this buys you. Reasoning needs types. A vault of untyped notes and plain wikilinks compiles to a flat graph of "links to" statements, and a reasoner derives nothing interesting from it. Run the "Install starter vault ontology" command, add `type:` frontmatter to the notes you care about, and use `property:: [[Target]]` for relations that mean something. The payoff scales with how much structure your vault actually carries.
+
## Install
Until the community-store listing lands, install with [BRAT](https://github.com/TfTHacker/obsidian42-brat) using this repo, or copy `main.js`, `manifest.json` and `styles.css` from the latest release into `.obsidian/plugins/open-ontologies/`.
diff --git a/docs/superpowers/specs/2026-08-14-obsidian-plugin-design.md b/docs/superpowers/specs/2026-08-14-obsidian-plugin-design.md
index c1333e0e..9c758fbc 100644
--- a/docs/superpowers/specs/2026-08-14-obsidian-plugin-design.md
+++ b/docs/superpowers/specs/2026-08-14-obsidian-plugin-design.md
@@ -13,12 +13,14 @@ An official Obsidian plugin that gives Obsidian users the **full** Open Ontologi
1. Someone running Obsidian can install one community plugin and get every Open Ontologies function, reasoners included, with zero manual binary installation.
2. Ontology files (`.ttl`, `.owl`, `.rdf`, `.jsonld`) stored in a vault are first-class: validate, reason, classify, diff, lint, query.
3. The vault itself (notes, frontmatter, tags, wikilinks) can be compiled to RDF, reasoned over, and SHACL-validated against shapes stored in the vault.
-4. Distribution through the official Obsidian community plugin store.
+4. **An LLM agent (Claude Code, Claude Desktop, or any MCP client) can query the reasoned vault graph over MCP**, so the "AI second brain" pattern gets entailment and validation instead of grep over Markdown.
+5. Distribution through the official Obsidian community plugin store.
## Non-goals (v1)
- **Mobile / WASM.** The causal layer (Python subprocess), planner (Fast Downward), embeddings (ONNX), and SQLite persistence are native-only. `isDesktopOnly: true`. A WASM lite core is a possible later phase only if demand appears.
- **AI chat.** Obsidian users bring their own LLM plugins; the engine stays MCP-native (no embedded LLM). The plugin is UI + orchestration, not a chat host.
+- **File access for agents.** We do not expose read/write/search over vault files to an LLM. `mcp-obsidian` plus the Local REST API plugin already does that well, and the two compose: an agent can hold both connections. Duplicating it would trade our only defensible advantage (reasoning) for a commodity.
- **Graph visualisation beyond the tree pane.** Obsidian's own graph view covers the vault plane.
## Repos and distribution
@@ -37,13 +39,15 @@ TypeScript Obsidian plugin. The engine is consumed **as released — zero Rust c
- Locates an engine binary in this order: user-configured path (settings) → previously downloaded copy in the plugin data dir → auto-download.
- Auto-download pulls the platform asset (macOS arm64/x64, Linux x86_64, Windows) from the engine repo's GitHub Releases, checksum-verified.
-- Spawns `open-ontologies serve-http` on an ephemeral localhost port; health-checks before reporting ready.
-- Lifecycle: kill on plugin unload; auto-restart on crash with capped backoff; retry on a new port if the chosen port is taken.
+- Spawns `open-ontologies serve-http --host 127.0.0.1 --port <configured> --token <generated>`; health-checks before reporting ready.
+- Port is the configured stable one (default 27125) so an external MCP client can be pointed at it once; falls back to an ephemeral port with a notice if it is occupied.
+- The bearer token is generated on first run, stored in plugin settings, and passed to every request. It is mandatory — see the CORS finding under "Agent-facing layer".
+- Lifecycle: kill on plugin unload; auto-restart on crash with capped backoff.
- Version management: the plugin declares a compatible engine semver range. On mismatch it blocks with a one-click update prompt — never silent skew.
### EngineClient
-- Thin typed wrapper over the engine's existing MCP streamable-HTTP transport (`serve-http`).
+- Thin typed wrapper over the engine's existing MCP streamable-HTTP transport (`serve-http`), sending `Authorization: Bearer <token>` on every request.
- Hand-curated TypeScript types for the ~15 workbench-critical tools (`onto_load`, `onto_validate`, `onto_shacl_check`, `onto_reason`, `onto_classify_el`, `onto_diff`, `onto_query`, `onto_lint`, `onto_apply`, `onto_save`, `onto_pack`, `onto_unpack`, …).
- Generic `call(tool, args)` escape hatch exposes the remaining tools, so **every** engine function is reachable from day one.
@@ -64,6 +68,42 @@ Default mapping (each rule overridable via a settings-editable YAML block):
Once synced, the vault graph is SHACL-validated against shapes stored in the vault and reasoned over; inferred triples and violations surface per-note.
+## Agent-facing layer: the second-brain use case
+
+The dominant Obsidian-plus-Claude pattern (Karpathy's LLM Wiki, popularised April 2026) wires Claude to the vault through the Local REST API community plugin and the `mcp-obsidian` MCP server. That stack gives an agent file read, file write, and text search. It does not give it entailment, typed structure, or validation.
+
+We do not compete with it, and we must not reimplement it. `mcp-obsidian` stays the file-access layer; Open Ontologies is the **reasoning layer next to it**. The claim is specific and defensible: an agent talking to this plugin gets a typed, entailed, SHACL-validated graph of the vault, and can ask questions no text search answers ("which notes assert a claim that contradicts a shape", "what is transitively part of this project", "which people are two hops from this topic").
+
+Four components make that real.
+
+**1. Stable, authenticated MCP endpoint.** The sidecar already *is* an MCP server, so no new server is needed. What it needs is an address an agent can be configured against once: a fixed loopback port (default 27125, chosen to sit beside Local REST API's 27124) instead of an ephemeral one, plus a bearer token the plugin generates on first run and passes as `--token`. Settings offers a one-click "copy MCP client config" that emits the correct JSON with the URL and header filled in.
+
+The token is **required, not optional**, because of a specific finding in the engine source: `serve-http` applies `tower_http::cors::CorsLayer::permissive()` to the router (`src/main.rs`, immediately before the `TcpListener::bind`). Permissive CORS on an ephemeral port that nothing knows about is a limited exposure; permissive CORS on a documented fixed port is not. Without a token, any web page open in the user's browser could issue cross-origin `POST http://127.0.0.1:27125/mcp` and read or mutate the vault graph. The token closes that: the bearer layer already wraps `/api` and `/mcp` (only `/health` sits outside it), so an unauthenticated cross-origin request is rejected before it reaches a tool. No Rust change is required — the capability exists and we must use it.
+
+The config the settings pane copies to the clipboard (verified against current Claude Code documentation; the same shape works in Claude Code's `.mcp.json`/`~/.claude.json` and in Claude Desktop's `claude_desktop_config.json`):
+
+```json
+{
+ "mcpServers": {
+ "open-ontologies": {
+ "type": "http",
+ "url": "http://127.0.0.1:27125/mcp",
+ "headers": { "Authorization": "Bearer <generated-token>" }
+ }
+ }
+}
+```
+
+The equivalent CLI form is `claude mcp add --transport http --header "Authorization: Bearer <token>" open-ontologies http://127.0.0.1:27125/mcp`. Both are offered in settings; the README documents the JSON form as primary because it is unambiguous across clients.
+
+**2. Auto-sync, so the graph an agent queries is current.** A stale graph is worse than no graph, because the agent cannot tell. On markdown create, modify, delete, or rename, the plugin schedules a debounced full vault re-sync (fires 10 seconds after the last change) in addition to the manual command. Full re-sync rather than per-note patching is deliberate for v1: deleting a note's prior triples correctly requires tracking what was asserted for it, and getting that wrong silently corrupts the graph. The engine handles graphs far larger than any vault (the repo's own LUBM benchmark runs at 1.29M triples), so a whole-vault reload is affordable. Incremental sync via `onto_reason_incremental` is a v2 optimisation, not a v1 requirement.
+
+**3. A starter vault ontology, because entailment over an untyped graph is vacuous.** This is the single biggest risk to the whole agent-facing story and it deserves stating plainly: most vaults have no `type:` frontmatter and no typed links. Mapped to RDF, such a vault is a bag of `vault:linksTo` triples, and OWL-RL over it infers nothing worth querying. The reasoning advantage is real only once notes carry types and relations.
+
+So the plugin ships a starter ontology and SHACL shape file, installed into the vault by a command, defining the vocabulary a second brain actually uses: `Note`, `Person`, `Project`, `Task`, `Source`, `Idea`, `Topic`, with `partOf` (transitive), `relatesTo` (symmetric), `authoredBy`, `references`, and `about`. Transitivity and symmetry are what give the reasoner something to derive. The same command seeds shapes that catch the structural mistakes a growing vault makes (a `Task` with no `partOf`, a `Source` with no URL).
+
+**4. Inferred connections, the visible payoff.** Obsidian shows explicit backlinks. This plugin surfaces **entailed** ones: triples true in the materialised closure that were never asserted. A command computes them for the active note (closure minus asserted set), lists them in the validation panel, and optionally writes them into the note under an "Inferred connections" heading. This is what "gets smarter every day" means concretely, and it is the feature no file-access MCP server can offer.
+
## UI surfaces (v1)
1. **Ontology tree pane** (right sidebar): class/property hierarchy of loaded graphs, Studio-style; click navigates to the defining file or note.
@@ -90,4 +130,12 @@ Once synced, the vault graph is SHACL-validated against shapes stored in the vau
## Decisions on version and security policy
- **Engine compatibility range:** the plugin pins `^MAJOR.MINOR` of the engine version it was tested against (e.g. `^1.1`), widening only after an explicit compatibility test in CI.
-- **Network exposure:** the sidecar must bind `127.0.0.1` only. Implementation includes verifying the current `serve-http` bind behaviour and, if it binds `0.0.0.0`, passing/adding a loopback-only flag before first release.
+- **Network exposure:** the sidecar binds `127.0.0.1` explicitly. Verified in the engine source: `serve-http` already defaults its `--host` to `127.0.0.1`, so this needs no Rust change; the plugin passes the flag anyway rather than depending on a default.
+- **Authentication is mandatory.** Because the router applies permissive CORS and the port is now fixed and documented, an unauthenticated endpoint would be reachable cross-origin from any page in the user's browser. The plugin generates a 32-byte hex token on first run and never starts the engine without one. There is no setting to disable it.
+- **Token handling:** stored in the plugin's own settings file inside the vault's `.obsidian` directory, displayed in settings only behind a reveal control, and regenerable with one click (which restarts the engine and invalidates any MCP client config the user copied earlier — the settings copy explains this).
+
+## Honest risks
+
+1. **Entailment over an untyped vault is vacuous.** Highest-severity risk to the agent-facing value proposition, and the reason the starter ontology is a v1 requirement rather than a nicety. A vault whose notes carry no types yields a graph of undifferentiated link triples, and the reasoning story collapses to marketing. Mitigation: ship the starter ontology, make typing a documented first step, and be honest in the README that the payoff scales with how typed the vault is.
+2. **Full re-sync cost.** Debounced whole-vault re-sync is O(vault) per edit burst. Comfortable for thousands of notes, not free for tens of thousands. Mitigation: 10-second debounce in v1, incremental sync in v2. Measure on a large vault before claiming a bound.
+3. **A second local endpoint is a second attack surface.** Addressed by the mandatory token above, but the honest framing is that we are adding a listening socket to the user's machine and that obliges us to default it shut.