Skip to content

Commit 94bb016

Browse files
committed
feat(ontology): W3C SHACL validation + PROV-O provenance (PRD-022)
Implements the Semantic Trust Layer across WS-0 through WS-5: - WS-0: Five SHACL shapes (knowledge-node, ontology-class, agent-node, bridge-record, inferred-axiom) in crates/visionclaw-ontology/shapes/ - WS-1: Dual-mode SHACL gate (Enforcing/Advisory) with severity mapping - WS-2: PROV-O reification emitter — every JSON-LD ingest and BC20 crossing produces queryable provenance triples in Oxigraph - WS-5: /api/ontology-physics/trust-status liveness canary - SPARQL migrations 0002/0003 bootstrap shapes and provenance graphs - ADR-127 accepted, PRD-022 evidence gate wired, DDD context added - WS-3/WS-4 (relay-mediated SPARQL federation) deferred to Phase 2 Co-Authored-By: jjohare <github@thedreamlab.uk>
1 parent dd68240 commit 94bb016

25 files changed

Lines changed: 1633 additions & 49 deletions

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ https://github.com/user-attachments/assets/f45c92dc-4800-4b57-a6e2-178da6bb0a38
2525

2626
---
2727

28-
**92 CUDA kernels · GPU clustering, anomaly detection and PageRank · Multi-user immersive XR · 88 agent skills · OWL 2 ontology governance · Nostr DID identity · Solid Pod sovereignty**
28+
**92 CUDA kernels · GPU clustering, anomaly detection and PageRank · Multi-user immersive XR · 88 agent skills · OWL 2 + SHACL ontology governance · W3C PROV-O provenance · Nostr DID identity · Solid Pod sovereignty**
2929

3030
---
3131

@@ -119,7 +119,7 @@ flowchart TB
119119
120120
subgraph Layer2["LAYER 2 — ORCHESTRATION"]
121121
Skills["88 Agent Skills\nClaude-Flow DAG Pipelines"]
122-
Ontology["OWL 2 EL Reasoning\nWhelk-rs Inference Engine"]
122+
Ontology["OWL 2 EL + SHACL\nWhelk-rs + PROV-O"]
123123
MCP["17 MCP Tools\nKnowledge Graph Read/Write"]
124124
GPU["GPU Compute\n92 CUDA Kernels"]
125125
end
@@ -147,6 +147,8 @@ flowchart TB
147147

148148
**Semantic Governance**
149149
- OWL 2 EL reasoning via Whelk-rs (EL++ inference)
150+
- W3C SHACL shape validation — dual-mode gate (enforcing on writes, advisory on reads)
151+
- W3C PROV-O provenance reified as queryable RDF in an append-only named graph
150152
- `subClassOf` → attraction, `disjointWith` → repulsion in GPU physics
151153
- Every ontology mutation creates a GitHub PR — human veto before commit
152154
- Content-addressed immutable provenance beads (Nostr)
@@ -676,7 +678,7 @@ Each context has its own aggregate roots, domain events, and anti-corruption lay
676678
| **Graph Store** | Oxigraph + SQLite | ADR-11 canonical persistence (SPARQL triple store) |
677679
| **Vector Memory** | RuVector PostgreSQL · pgvector | 1.17M+ entries · HNSW 384-dim · MiniLM-L6-v2 · 61µs search |
678680
| **GPU** | CUDA 13.1 · cudarc | 92 kernel functions · 6,585 LOC · PTX ISA auto-downgrade |
679-
| **Ontology** | OWL 2 EL · Whelk-rs | EL++ subsumption · consistency checking |
681+
| **Ontology** | OWL 2 EL · Whelk-rs · SHACL | EL++ subsumption · consistency checking · W3C shape validation · PROV-O provenance |
680682
| **Multi-User** | Vircadia World Server | Avatar sync · spatial HRTF audio · collaborative editing |
681683
| **Voice** | LiveKit SFU · turbo-whisper · Kokoro | CUDA STT · TTS · Opus 48kHz · 4-plane routing |
682684
| **Identity** | Nostr NIP-07/NIP-98 · DID:Nostr | Browser extension signing · NIP-26 delegation · W3C key rotation |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Migration 0002: Bootstrap the SHACL shapes named graph (PRD-022 WS-0).
2+
#
3+
# Creates urn:ngm:graph:shapes and loads a sentinel triple so the graph
4+
# is discoverable via SPARQL ASK. The actual shape triples are loaded
5+
# programmatically from the embedded .ttl files at startup — this
6+
# migration only ensures the graph exists and is queryable.
7+
#
8+
# Idempotent: INSERT DATA is additive; re-running is a no-op if the
9+
# sentinel already exists.
10+
11+
INSERT DATA {
12+
GRAPH <urn:ngm:graph:shapes> {
13+
<urn:ngm:shape:catalogue>
14+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
15+
<http://www.w3.org/ns/shacl#Schema> .
16+
17+
<urn:ngm:shape:catalogue>
18+
<http://www.w3.org/2000/01/rdf-schema#comment>
19+
"SHACL shape catalogue for VisionClaw domain types (PRD-022)." .
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Migration 0003: Bootstrap the PROV-O provenance named graph (PRD-022 WS-2).
2+
#
3+
# Creates urn:ngm:graph:provenance as an append-only audit trail for
4+
# reified PROV-O activity triples. The sentinel triple marks the graph
5+
# as a provenance container.
6+
#
7+
# INVARIANT: This graph accepts only INSERT DATA. No DELETE, DROP, or
8+
# CLEAR operations are permitted against it. Enforcement is at the
9+
# handler level (validate_read_only_sparql + provenance-specific guard).
10+
#
11+
# Idempotent: INSERT DATA is additive.
12+
13+
INSERT DATA {
14+
GRAPH <urn:ngm:graph:provenance> {
15+
<urn:ngm:provenance:catalogue>
16+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
17+
<http://www.w3.org/ns/prov#Collection> .
18+
19+
<urn:ngm:provenance:catalogue>
20+
<http://www.w3.org/2000/01/rdf-schema#comment>
21+
"Append-only PROV-O provenance trail for VisionClaw (PRD-022)." .
22+
}
23+
}

crates/visionclaw-adapters/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ pub use sparql_migrations::{run_pending as run_sparql_migrations, MigrationError
4242
// WS-1 / ADR-100 — standards-grade RDF round-trip serialisation over oxigraph's
4343
// bundled oxrdfio (Turtle / JSON-LD / N-Quads). No new dependency.
4444
pub mod rdf_serializer;
45+
46+
// PRD-022 WS-2 — PROV-O provenance reification emitter. Reifies activity
47+
// URNs as RDF triples in the append-only urn:ngm:graph:provenance graph.
48+
pub mod provenance_emitter;
49+
pub use provenance_emitter::{reify_activity, ActivityRecord, ProvenanceError};

crates/visionclaw-adapters/src/oxigraph_ontology_repository.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ pub const GRAPH_ONTOLOGY_INFERRED: &str = "urn:ngm:graph:ontology:inferred";
4848
pub const GRAPH_KNOWLEDGE: &str = "urn:ngm:graph:knowledge";
4949
pub const GRAPH_AGENT: &str = "urn:ngm:graph:agent";
5050

51+
/// PRD-022 trust-layer named graphs.
52+
/// `:shapes` holds W3C SHACL shape triples loaded from .ttl files at startup.
53+
/// `:provenance` holds append-only PROV-O activity triples (reified provenance).
54+
pub const GRAPH_SHAPES: &str = "urn:ngm:graph:shapes";
55+
pub const GRAPH_PROVENANCE: &str = "urn:ngm:graph:provenance";
56+
5157
/// WS-9 derived named graphs. These are the ONLY graphs writable through the
5258
/// fenced `/api/ontology/derived` path: `:summary` holds approval-driven
5359
/// summary triples (broker write-back consequences), `:observed` holds

0 commit comments

Comments
 (0)