@prefix ckp:  <https://conceptkernel.org/ontology/v3.8/core#> .
@prefix sh:   <http://www.w3.org/ns/shacl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .

#######################################################################
# CKP CORE ONTOLOGY — shipped inside the `conceptkernel` extension.
# Loaded into pgRDF graph urn:ckp:core at CREATE EXTENSION.
# Governs the protocol's OWN operations: every governed write is
# validated against these shapes at commit.
# Split files under ontology/*.ttl are the first manual modeling pass
# for rc-07/rc-08 linkage work. ckp.boot() still loads only core.ttl,
# so this file remains authoritative for shipped runtime semantics.
#######################################################################

# ---- Classes -------------------------------------------------------

ckp:Kernel      a rdfs:Class ; rdfs:comment "A versioned, ontology-defined unit of behaviour." .
ckp:Organ       a rdfs:Class ; rdfs:comment "CK | TOOL | DATA." .
ckp:Affordance  a rdfs:Class ; rdfs:comment "Binds an inbound NATS topic to an action." .
ckp:LedgerEntry a rdfs:Class ; rdfs:comment "Append-only HMAC-authenticated audit record." .
ckp:Proof       a rdfs:Class ; rdfs:comment "Verifiable HMAC-backed attestation about an instance." .
ckp:Provenance  a rdfs:Class ; rdfs:comment "PROV-O subset for derivation." .

# Governance type plane (v3.9 §9 / CI-D-6)
ckp:Proposal    a rdfs:Class ; rdfs:comment "A proposed governed type change — pending until quorum applies it." .
ckp:Vote        a rdfs:Class ; rdfs:comment "A sealed vote about a Proposal." .
ckp:QuorumLevel a rdfs:Class ; rdfs:comment "A named quorum requirement for a governed change." .
ckp:Grant       a rdfs:Class ; rdfs:comment "Binds a role to a Permission (domain × action × target)." .
ckp:Transition  a rdfs:Class ; rdfs:comment "A sealed allowed (from → to) edge in a kernel's transition map." .

# ---- Properties ----------------------------------------------------

ckp:organKind   a owl:DatatypeProperty .   # "ck" | "tool" | "data"
ckp:dataSubstrate a owl:DatatypeProperty .  # "jsonb" | "age" | "jsonb,age"

ckp:inTopic     a owl:DatatypeProperty .
ckp:outTopic    a owl:DatatypeProperty .
ckp:inShape     a owl:ObjectProperty .
ckp:sparql      a owl:DatatypeProperty .
ckp:plane       a owl:DatatypeProperty .   # v3.9 §2.2: "instance" | "governance" — the dispatch plane route (CI-B-5)
ckp:epoch       a owl:DatatypeProperty .   # v3.9 §5.3: compile epoch on a sealed affordance — stale-plan detection (CI-B-5)
ckp:delegate    a owl:DatatypeProperty .   # v3.9 §2.2: a SEALED delegation fact (boolean) — {delegate:true}, not an absence (CI-B-4)

ckp:about       a owl:ObjectProperty .
ckp:affordance  a owl:ObjectProperty .
ckp:delivery    a owl:ObjectProperty .
ckp:validation  a owl:ObjectProperty .
ckp:delegation  a owl:ObjectProperty .
ckp:bodySha     a owl:DatatypeProperty .
ckp:sig         a owl:DatatypeProperty .
ckp:prev        a owl:DatatypeProperty .
ckp:ts          a owl:DatatypeProperty .

ckp:method      a owl:DatatypeProperty .
ckp:digest      a owl:DatatypeProperty .
ckp:verifiedAt  a owl:DatatypeProperty .

# Governance type plane (v3.9 §9 / CI-D-6)
ckp:proposalState  a owl:DatatypeProperty .   # "pending" | "applied" | "rejected"
ckp:proposalOp     a owl:DatatypeProperty .   # add_class | add_property | modify_shape_constraint | add_affordance | set_transition_map | set_quorum | set_materialize_policy
ckp:requiresQuorum a owl:DatatypeProperty .   # integer vote threshold for a governed change
ckp:voteValue      a owl:DatatypeProperty .   # "approve" | "reject"
ckp:role           a owl:DatatypeProperty .   # RBAC role name
ckp:grant          a owl:ObjectProperty .     # → ckp:Grant
ckp:permDomain     a owl:DatatypeProperty .   # Permission domain
ckp:permAction     a owl:DatatypeProperty .   # Permission action
ckp:permTarget     a owl:DatatypeProperty .   # Permission target
ckp:fromState      a owl:DatatypeProperty .   # transition-map source state
ckp:toState        a owl:DatatypeProperty .   # transition-map destination state

# ---- SHACL shapes — the protocol governs itself --------------------

ckp:KernelShape a sh:NodeShape ;
  sh:targetClass ckp:Kernel ;
  sh:property [ sh:path rdfs:label   ; sh:minCount 1 ; sh:datatype xsd:string ] ;
  sh:property [ sh:path ckp:dataSubstrate ; sh:minCount 1 ;
                sh:in ( "jsonb" "age" "jsonb,age" ) ] .

ckp:AffordanceShape a sh:NodeShape ;
  sh:targetClass ckp:Affordance ;
  sh:property [ sh:path ckp:inTopic ; sh:minCount 1 ; sh:datatype xsd:string ] ;
  sh:property [ sh:path ckp:inShape ; sh:maxCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path ckp:outTopic ; sh:maxCount 1 ; sh:datatype xsd:string ] ;
  # v3.9 §2.2 / §9 — the dispatch plane + compile epoch on each affordance. Optional for the
  # delta (existing affordances predate them; CI-B-2 defaults a missing plane to "instance");
  # if present, plane MUST be one of the two enum values.
  sh:property [ sh:path ckp:plane ; sh:maxCount 1 ; sh:in ( "instance" "governance" ) ] ;
  sh:property [ sh:path ckp:epoch ; sh:maxCount 1 ; sh:datatype xsd:integer ] ;
  sh:property [ sh:path ckp:delegate ; sh:maxCount 1 ; sh:datatype xsd:boolean ] .

# A ledger entry MUST carry a non-empty HMAC signature and a chain pointer.
ckp:LedgerEntryShape a sh:NodeShape ;
  sh:targetClass ckp:LedgerEntry ;
  sh:property [ sh:path ckp:about   ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path ckp:bodySha ; sh:minCount 1 ; sh:datatype xsd:string ;
                sh:pattern "^[0-9a-f]{64}$" ] ;
  sh:property [ sh:path ckp:sig     ; sh:minCount 1 ; sh:datatype xsd:string ;
                sh:minLength 16 ] ;
  sh:property [ sh:path ckp:ts      ; sh:minCount 1 ; sh:datatype xsd:dateTime ] .

# A proof MUST carry the shipped HMAC method and a digest, and be verifiable.
ckp:ProofShape a sh:NodeShape ;
  sh:targetClass ckp:Proof ;
  sh:property [ sh:path ckp:about     ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path ckp:method    ; sh:minCount 1 ; sh:datatype xsd:string ;
                sh:in ( "hmac+sha256" ) ] ;
  sh:property [ sh:path ckp:digest    ; sh:minCount 1 ; sh:datatype xsd:string ;
                sh:pattern "^[0-9a-f]{64}$" ] ;
  sh:property [ sh:path ckp:verifiedAt ; sh:minCount 1 ; sh:datatype xsd:dateTime ] .

# ---- Governance shapes (v3.9 §9 / CI-D-6) — the type plane governs itself ----

# A Proposal is DATA about a future type change — pending until quorum applies it.
ckp:ProposalShape a sh:NodeShape ;
  sh:targetClass ckp:Proposal ;
  sh:property [ sh:path ckp:about ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path ckp:proposalState ; sh:minCount 1 ;
                sh:in ( "pending" "applied" "rejected" ) ] ;
  sh:property [ sh:path ckp:requiresQuorum ; sh:maxCount 1 ; sh:datatype xsd:integer ] .

# A Vote is sealed BY an identity and is ABOUT a Proposal.
ckp:VoteShape a sh:NodeShape ;
  sh:targetClass ckp:Vote ;
  sh:property [ sh:path ckp:about ; sh:minCount 1 ; sh:nodeKind sh:IRI ] ;
  sh:property [ sh:path ckp:voteValue ; sh:minCount 1 ;
                sh:in ( "approve" "reject" ) ] .

# A Grant binds a role to a Permission (domain × action × target).
ckp:GrantShape a sh:NodeShape ;
  sh:targetClass ckp:Grant ;
  sh:property [ sh:path ckp:role ; sh:minCount 1 ; sh:datatype xsd:string ] ;
  sh:property [ sh:path ckp:permDomain ; sh:minCount 1 ; sh:datatype xsd:string ] ;
  sh:property [ sh:path ckp:permAction ; sh:minCount 1 ; sh:datatype xsd:string ] ;
  sh:property [ sh:path ckp:permTarget ; sh:minCount 1 ; sh:datatype xsd:string ] .

# A Transition is a sealed allowed (from → to) edge in a kernel's transition map.
ckp:TransitionShape a sh:NodeShape ;
  sh:targetClass ckp:Transition ;
  sh:property [ sh:path ckp:fromState ; sh:minCount 1 ; sh:datatype xsd:string ] ;
  sh:property [ sh:path ckp:toState ; sh:minCount 1 ; sh:datatype xsd:string ] .
