# ConceptKernel Base Instance Shapes Ontology
# Version: v3.6
# Date: 2026-04-06
# Purpose: OWL classes for base instance shapes — InstanceManifest, SealedInstance, LedgerEntry

@prefix : <https://conceptkernel.org/ontology/v3.6/> .
@prefix ckp: <https://conceptkernel.org/ontology/v3.6/> .
@prefix bfo: <http://purl.obolibrary.org/obo/BFO_> .
@prefix iao: <http://purl.obolibrary.org/obo/IAO_> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix prov: <http://www.w3.org/ns/prov#> .

<https://conceptkernel.org/ontology/v3.6/base-instances> a owl:Ontology ;
    dc:title "ConceptKernel Base Instance Shapes Ontology" ;
    dc:description "OWL classes defining the base instance shapes for InstanceManifest, SealedInstance, and LedgerEntry" ;
    dcterms:created "2026-04-06"^^xsd:date ;
    dcterms:modified "2026-04-06"^^xsd:date ;
    owl:versionInfo "v3.6" ;
    dcterms:creator "Peter Styk <peter@conceptkernel.org>" ;
    rdfs:seeAlso <https://conceptkernel.org> ;
    rdfs:seeAlso <https://github.com/ConceptKernel> ;
    rdfs:comment "Defines the canonical instance structures. InstanceManifest and LedgerEntry grounded in iao:DataItem." ;
    owl:imports <https://conceptkernel.org/ontology/v3.6/> .

#################################################################
#    InstanceManifest — base class for all instances
#################################################################

ckp:InstanceManifest a owl:Class ;
    rdfs:subClassOf iao:0000027 ;  # iao:DataItem (via ckp:Instance reclassification)
    rdfs:label "Instance Manifest"@en ;
    rdfs:comment "The base shape for all CKP instances. An immutable data item produced by a kernel action. Every instance directory contains a manifest.json conforming to this shape."@en ;
    dc:description "Stored at storage/instances/i-{identifier}/manifest.json" .

### InstanceManifest Properties

ckp:instance_id a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range xsd:string ;
    rdfs:label "instance ID"@en ;
    rdfs:comment "Unique identifier for the instance, format: i-{slug}-{epoch}"@en .

ckp:kernel_class a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range xsd:string ;
    rdfs:label "kernel class"@en ;
    rdfs:comment "The class name of the kernel that produced this instance (e.g., LOCAL.ClaudeCode)"@en .

ckp:kernel_id a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range xsd:string ;
    rdfs:label "kernel ID"@en ;
    rdfs:comment "The unique identifier (GUID) of the kernel that produced this instance"@en .

ckp:created_at a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range xsd:dateTime ;
    rdfs:label "created at"@en ;
    rdfs:comment "ISO 8601 timestamp of instance creation"@en .

### Provenance linkage (PROV-O aligned)

ckp:instanceWasGeneratedBy a owl:ObjectProperty , owl:FunctionalProperty ;
    rdfs:subPropertyOf prov:wasGeneratedBy ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range prov:Activity ;
    rdfs:label "was generated by"@en ;
    rdfs:comment "The action/activity that generated this instance (prov:wasGeneratedBy)"@en .

ckp:instanceWasAttributedTo a owl:ObjectProperty , owl:FunctionalProperty ;
    rdfs:subPropertyOf prov:wasAttributedTo ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range prov:Agent ;
    rdfs:label "was attributed to"@en ;
    rdfs:comment "The kernel/agent responsible for this instance (prov:wasAttributedTo)"@en .

ckp:instanceGeneratedAtTime a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:subPropertyOf prov:generatedAtTime ;
    rdfs:domain ckp:InstanceManifest ;
    rdfs:range xsd:dateTime ;
    rdfs:label "generated at time"@en ;
    rdfs:comment "Timestamp when this instance was generated (prov:generatedAtTime)"@en .

#################################################################
#    SealedInstance — finalized instance with data and refs
#################################################################

ckp:SealedInstance a owl:Class ;
    rdfs:subClassOf ckp:InstanceManifest ;
    rdfs:label "Sealed Instance"@en ;
    rdfs:comment "A finalized, immutable instance that has been sealed with data, tool reference, and CK reference. Once sealed, the instance and its contents cannot be modified."@en ;
    dc:description "Sealed instances contain data.json, and link back to tool/ and CK loop references" .

### SealedInstance Properties

ckp:data a owl:DatatypeProperty ;
    rdfs:domain ckp:SealedInstance ;
    rdfs:range xsd:string ;
    rdfs:label "data"@en ;
    rdfs:comment "JSON-serialized output data of the sealed instance (stored as data.json). Required — every SealedInstance must contain data."@en .

ckp:tool_ref a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:SealedInstance ;
    rdfs:range xsd:string ;
    rdfs:label "tool reference"@en ;
    rdfs:comment "Reference to the tool loop (processor) that produced this instance, e.g., tool/processor.py"@en .

ckp:ck_ref a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:SealedInstance ;
    rdfs:range xsd:string ;
    rdfs:label "CK reference"@en ;
    rdfs:comment "Reference to the CK loop (conceptkernel.yaml) identity at the time this instance was sealed"@en .

#################################################################
#    LedgerEntry — append-only action log
#################################################################

ckp:LedgerEntry a owl:Class ;
    rdfs:subClassOf iao:0000027 ;  # iao:DataItem
    rdfs:label "Ledger Entry"@en ;
    rdfs:comment "An append-only log entry recording a state transition or action event. Stored in storage/ledger/ as JSONL files, one entry per line."@en ;
    dc:description "Stored at storage/ledger/actions-{date}.jsonl" .

### LedgerEntry Properties

ckp:ledgerTimestamp a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:LedgerEntry ;
    rdfs:range xsd:dateTime ;
    rdfs:label "timestamp"@en ;
    rdfs:comment "ISO 8601 timestamp of when this ledger event occurred"@en .

ckp:ledgerEvent a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:LedgerEntry ;
    rdfs:range xsd:string ;
    rdfs:label "event"@en ;
    rdfs:comment "The event type or action name recorded in this ledger entry (e.g., spawn, seal, context)"@en .

ckp:ledgerBefore a owl:DatatypeProperty ;
    rdfs:domain ckp:LedgerEntry ;
    rdfs:range xsd:string ;
    rdfs:label "before"@en ;
    rdfs:comment "JSON-serialized state before the event (for state transitions)"@en .

ckp:ledgerAfter a owl:DatatypeProperty ;
    rdfs:domain ckp:LedgerEntry ;
    rdfs:range xsd:string ;
    rdfs:label "after"@en ;
    rdfs:comment "JSON-serialized state after the event (for state transitions)"@en .

#################################################################
#################################################################

#################################################################
#    v3.6: TaskInstance — instance shape for consensus-generated tasks
#################################################################

ckp:TaskInstance a owl:Class ;
    rdfs:subClassOf ckp:InstanceManifest ;
    rdfs:label "Task Instance"@en ;
    rdfs:comment "An instance shape for consensus-generated tasks. Tasks are concrete work items with an instruction, target file, constraints, executor, and version pin. Generated by CK.Consensus approve action."@en ;
    dc:description "v3.6 addition. Stored at storage/tasks/{task_id}.yaml" .

### TaskInstance Properties

ckp:taskId a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "task ID"@en ;
    rdfs:comment "Unique identifier for this task, format: T-{uuid4_prefix}"@en .

ckp:decisionId a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "decision ID"@en ;
    rdfs:comment "The consensus decision that generated this task"@en .

ckp:targetFile a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "target file"@en ;
    rdfs:comment "The file path that this task modifies"@en .

ckp:taskInstruction a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "instruction"@en ;
    rdfs:comment "The instruction for the executor (human-readable specification of what to do)"@en .

ckp:taskStatus a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "task status"@en ;
    rdfs:comment "Task lifecycle status: pending, executing, completed, failed"@en .

ckp:taskVersionPin a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "version pin"@en ;
    rdfs:comment "Git commit hash — task applies to this specific kernel version"@en .

ckp:taskExecutor a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:TaskInstance ;
    rdfs:range xsd:string ;
    rdfs:label "executor"@en ;
    rdfs:comment "The executor type: headless-claude-code, manual, automated"@en .

#################################################################
#    v3.6: ConversationInstance — instance shape for multi-turn sessions
#################################################################

ckp:ConversationInstance a owl:Class ;
    rdfs:subClassOf ckp:InstanceManifest ;
    rdfs:label "Conversation Instance"@en ;
    rdfs:comment "An instance shape for recording multi-turn LLM conversation sessions. Stores the conversation context, stream events, and final result. Produced when agent-type kernels execute conversational actions."@en ;
    dc:description "v3.6 addition. Stored at storage/instances/i-{trace}-{ts}/conversation/" .

### ConversationInstance Properties

ckp:conversationTraceId a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:ConversationInstance ;
    rdfs:range xsd:string ;
    rdfs:label "trace ID"@en ;
    rdfs:comment "Trace identifier linking all messages in this conversation"@en .

ckp:conversationPersona a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:ConversationInstance ;
    rdfs:range xsd:string ;
    rdfs:label "persona"@en ;
    rdfs:comment "The persona template used during this conversation"@en .

ckp:conversationModel a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:ConversationInstance ;
    rdfs:range xsd:string ;
    rdfs:label "model"@en ;
    rdfs:comment "The LLM model used for this conversation (e.g., sonnet, opus)"@en .

ckp:conversationTurnCount a owl:DatatypeProperty , owl:FunctionalProperty ;
    rdfs:domain ckp:ConversationInstance ;
    rdfs:range xsd:integer ;
    rdfs:label "turn count"@en ;
    rdfs:comment "Number of conversation turns (assistant messages) in this session"@en .

#################################################################
# End of ConceptKernel Base Instance Shapes Ontology v3.6
#################################################################
