Skip to content

CK.Project, CK.Lib.Py, and CK.Lib.Js

CK.Project -- Project Declaration

Purpose

A CK.Project declares the existence, scope, and configuration of a project -- a coherent collection of kernels under a shared domain. It answers: "What kernels exist, what domain do they serve, how are they stored, and how are users authenticated?"

CK.Project is a static kernel because it holds only declarations; it has no processor that executes actions at runtime. CK.Operator COMPOSES it to access project data.

PropertyValue
URNckp://Kernel#CK.Project:v1.0
Typestatic
GovernanceSTRICT
ArchetypeDeclarator

Project Instance Structure

Each project is an instance stored at CK.Project/storage/instances/{hostname}/data.yaml. The hostname is the project's identity -- it determines DNS routing, namespace naming, and filer path prefixes.

yaml
# CK.Project instance: delvinator.tech.games
domain: tech.games
serving:
  subdomain: delvinator
  hostname: delvinator.tech.games
storage: volume
gateway:
  parentRef:
    name: multi-domain-gateway
    namespace: gateway-system
backends:
  nats:
    endpoint: nats://nats.nats.svc:4222
    wssEndpoint: wss://stream.tech.games

Required Fields

A conformant CK.Project instance MUST declare:

FieldTypeDescription
domainstringDNS domain for all kernels in the project
serving.subdomainstringSubdomain prefix; namespace derived as ck-{subdomain}
storageenumDeployment method: volume, filer, or configmap
gateway.parentRef.namestringKubernetes Gateway API gateway name
gateway.parentRef.namespacestringGateway namespace

AuthConfig

CK.Project instances MAY declare an auth block for OIDC identity provider configuration. Identity is a project-scoped concern: each project has its own realm, client, and access policies.

yaml
auth:
  provider: keycloak         # keycloak | none
  instance: keycloak-name    # Keycloak CR on cluster
  realm: realm-name          # Keycloak realm name
  client_id: ck-web          # OIDC public client
  issuer_url: https://id.example.com/realms/realm-name
  create_realm: false        # true = operator creates realm via KeycloakRealmImport
  redirect_uris: []          # REQUIRED if create_realm is true
  web_origins: []            # REQUIRED if create_realm is true

Two modes:

ModeBehaviourKeycloak Permissions
Reuse (create_realm: false)Operator injects existing issuer URL into deployments, verifies OIDC endpointNone (zero write)
Create (create_realm: true)Operator creates KeycloakRealmImport CR; Keycloak operator provisions realmget, list, create on keycloakrealmimports

On teardown, the KeycloakRealmImport is RETAINED. Identity outlives compute.

Auth Details

For the full authentication flow including JWT verification, token lifecycle, and grants enforcement, see Auth.

Ontology Publishing

Each project SHOULD publish a Layer 2 ontology importing CKP Layer 1:

yaml
id: https://example.org/ontology/v1/{project-name}
prefixes:
  ckp: https://conceptkernel.org/ontology/v3.6/
  bfo: http://purl.obolibrary.org/obo/BFO_
  prov: http://www.w3.org/ns/prov#
  proj: https://example.org/ontology/v1/

classes:
  ProjectKernel:
    is_a: ckp:Kernel
    attributes:
      project_name: { range: string, required: true }
      kernel_count: { range: integer }

CK.Project Conformance

CriterionLevel
CK.Project MUST declare domain, serving.subdomain, storage, gateway.parentRefREQUIRED
Each project SHOULD publish a Layer 2 ontologyRECOMMENDED
Project ontology.yaml MUST import CKP Layer 1REQUIRED
If auth.provider is keycloak, realm, client_id, issuer_url MUST be presentREQUIRED
If create_realm is true, redirect_uris and web_origins MUST be presentREQUIRED

CK.Lib.Py -- Python Runtime

Purpose

CK.Lib.Py (conceptkernel on PyPI) is the canonical Python runtime library for CKP. Every Python-based Concept Kernel MUST use CK.Lib.Py (or a compatible implementation) to participate in the CKP ecosystem. The library codifies the CKP contract -- three-loop separation, instance lifecycle, PROV-O provenance, edge composition, RBAC -- as executable code.

PropertyValue
Packageconceptkernel on PyPI
Importimport cklib
Python>= 3.11
Dependenciespyyaml, nats-py, httpx, pyjwt, fastapi, uvicorn
LicenseMIT

Architecture

CK.Lib.Py implements the server-side CKP runtime. It runs on cluster nodes or local machines, connects to NATS via nats-py (native TCP or WSS), has filesystem access to storage/, and writes instances, proofs, and ledger entries.

CLUSTER / LOCAL MACHINE (Python, nats-py)
  KernelProcessor          -- ckp:Kernel
  NatsKernelLoop           -- ckp:NATSListening
  instance.py              -- ckp:InstanceManifest, ckp:SealedInstance
  prov.py                  -- prov:Activity chain
  actions.py               -- ckp:Edge + ckp:RelationshipType

18 Modules

#ModuleOntology ClassPurposeKey Exports
1processor.pyckp:KernelBase class for all kernel processorsKernelProcessor
2events.pyckp:ActionAction handler decorator and typed event emissionon(), emit()
3instance.pyckp:InstanceManifest, ckp:SealedInstanceInstance lifecycle: create, seal, ledger, proofcreate_instance(), seal_instance(), append_ledger()
4ledger.pyckp:LedgerEntryKernel-wide append-only JSONL action loglog_action(), read_ledger()
5schema.pyckp:SealedInstance validationLinkML ontology.yaml loading and validationload_schema(), validate_instance(), has_schema()
6context.pyN/AThree-loop-aware context builderbuild_context()
7capacity.pyN/AConcurrency control via file-based capacity managementcheck_capacity(), acquire(), release()
8occurrent.pyckp:Occurrent (BFO:0000015)Action substeps with PROV-O proof and hash chainsActionOccurrent, StepRecord
9edges.pyckp:Edge, ckp:RelationshipTypeEdge subscription materialisation for NATSmaterialise_edge_subscriptions()
10actions.pyckp:Action, rbac.ttlAction type resolution, composition, RBACresolve_action_type(), check_access(), get_effective_actions()
11dispatch.pyckp:EdgeCommunicationLocal inter-kernel action dispatch and FIFO queuesend_action(), queue_action(), run_queue()
12serve.pyckp:WebServing, ckp:APIServingFastAPI HTTP server wrapping @on handlersKernelServer
13auth.pyrbac.ttlKeycloak JWT verification + API token fallbackCKAuth
14urn.pyCKP URN schemeCKP URN parser, validator, builder (17 entity types)parse_urn(), validate_urn(), build_urn()
15prov.pyprov:ActivityPROV-O session recording for any kernelProvChain, Session, verified_action()
16execution.pyckp:ProofRecord, ckp:ProofCheckMulti-step execution proofs with hash chainshash_step(), build_execution_proof(), verify_chain()
17entities.pyN/AIn-memory entity store with code-based lookupEntityManager
18nats_loop.pyckp:NATSListeningNATS subscriber loop implementing CK processing cycleNatsKernelLoop

KernelProcessor Base Class

KernelProcessor is the base class that every Python kernel subclasses. On construction it reads conceptkernel.yaml (CK loop), resolves paths, and prepares the handler dispatch table.

MemberKindDescription
KernelProcessor(ck_dir=None)constructorInitialise; loads identity from conceptkernel.yaml
.identitypropertyLazy-loaded parsed identity dict
.namepropertymetadata.name from identity
.urnpropertymetadata.urn from identity
.kernel_typepropertyqualities.type (e.g., node:hot)
.governancepropertyqualities.governance_mode
.handle_message(msg)methodDispatch to @on handler; resolution: own -> built-in -> composed -> error
.listen()methodStart NatsKernelLoop subscriber (blocking)
.serve(port=8901)methodStart FastAPI HTTP server via KernelServer
KernelProcessor.run()classmethodCLI entry point: --status, --listen, --serve, --action, --data

NatsKernelLoop

The NATS processing cycle enforces three-loop separation at the message level:

  1. Connect to NATS (TCP or WSS)
  2. Subscribe to input.{KernelName}
  3. For each message:
    • Parse headers (Trace-Id, X-Kernel-ID, X-User-ID, Authorization)
    • Verify JWT if Authorization: Bearer present; fallback to anonymous
    • RBAC grants check via check_access()
    • Dispatch to handler_fn(body) (supports sync and async handlers)
    • Write instance record to storage/instances/i-{trace}-{ts}/message.json
    • Publish result to result.{KernelName} with headers
    • Publish event to event.{KernelName}

The handler returns data; the platform writes it. This is the three-loop contract in action.

Processor Pattern

python
from cklib import KernelProcessor, on, emit

class MyKernel(KernelProcessor):
    @on("my.action")
    def handle(self, data):
        result = {"answer": 42}
        return emit("ActionCompleted", result=result)

if __name__ == "__main__":
    MyKernel.run()
    # CLI modes: --status, --action, --listen, --serve

CK.Lib.Py Conformance

CriterionLevel
CK.Lib.Py MUST enforce three-loop separationREQUIRED
Handlers MUST NOT write to storage/ directlyREQUIRED
JWT verification MUST occur before handler dispatchREQUIRED
PROV-O provenance MUST be generated for every instanceREQUIRED
Edge composition MUST derive from conceptkernel.yaml declarationsREQUIRED
Kernel processors MUST output structured JSON logs to stdoutREQUIRED
All 18 modules MUST be importable from the cklib packageREQUIRED

CK.Lib.Js -- JavaScript Client

Purpose

CK.Lib.Js (@conceptkernel/cklib on npm) is the canonical JavaScript client library for CKP. It runs in browsers and Node.js environments, connecting to NATS via WebSocket Secure (WSS). CK.Lib.Js provides no filesystem access -- it is a pure messaging client.

The browser is an isolated client, like any CLI tool. It publishes action messages to input.* topics and subscribes to result.* and event.* topics. All mutations happen server-side in kernel processors. The client never reads or writes kernel filesystems.

PropertyValue
Package@conceptkernel/cklib on npm
Main entryck-client.js
TypeESM module
Dependenciesnats.ws ^1.30.3
LicenseMIT

12 Modules

#ModuleExport PathOntology GroundingPurpose
1ck-client.js. / ./clientckp:NATSBrowserClientCore NATS WSS client; connection, auth, send, subscribe
2ck-page.js./pageckp:InlineKernelPage harness; auto-detects kernel, renders chrome
3ck-bus.js./busckp:EdgeCommunicationIn-browser event bus for decoupled component communication
4ck-kernel.js./kernel--Kernel-specific CSS variables and theming
5ck-registry.js./registryckp:ProjectKernel registry for multi-kernel page composition
6ck-runtime.js./runtime--Client-side runtime utilities
7ck-materializer.js./materializer--Client-side resource materialisation
8ck-store.js./store--Client-side state persistence (localStorage + server filer)
9ck-shapes.js./shapessh:NodeShapeSHACL shape rendering and validation UI
10ck-anim.js./anim--Animation engine for kernel visualisations
11ck-anim-grammar.js(internal)--Animation grammar parser
12ck-sound.js./sound--Web Audio API integration for kernel sound effects

CKClient API

CKClient is the core NATS WSS client. It manages connection lifecycle, authentication escalation, and message send/receive.

javascript
const ck = new CKClient({
  kernel: "Delvinator.Core",
  wssEndpoint: "wss://stream.tech.games",
  authEndpoint: "https://id.tech.games",
  realm: "techgames",
  clientId: "ck-web"
})
MethodReturnsDescription
connect()Promise<boolean>Connect to NATS WSS, auto-subscribe to result.{kernel} and event.{kernel}
send(data)Promise<string>Publish to input.{kernel}; returns traceId
login(username, password)Promise<string>Keycloak password grant; returns userId
logout()voidDowngrade to anonymous identity
disconnect()Promise<void>Unsubscribe all, drain connection
on(event, fn)voidSubscribe to: "result", "event", "status", "error"
off(event, fn)voidUnsubscribe from event

Authentication Lifecycle

  1. Anonymous connect: Generate anon_{random_hex} identity, connect to WSS, subscribe to result/event topics
  2. Login escalation: POST to Keycloak token endpoint (grant_type=password), upgrade identity, attach JWT to all subsequent messages
  3. Token refresh: Auto-refresh when access token is within 30 seconds of expiry. On failure, revert to anonymous
  4. Logout: Downgrade to anonymous identity without NATS reconnect

CKPage -- Web Console

CKPage is the unified page harness (console.html) that auto-detects the kernel from /ontology.yaml, connects NATS via CKClient, and renders the standard CKP chrome.

Three-panel layout:

PanelWidthContent
Action sidebar160pxActions from kernel's spec.actions, NATS topics, message history
Parameter form280pxPer-action input fields, JSON preview, send button
ResultsflexNATS messages in chat, body, or envelope view

For more on the web console, see Web Shell.

CK.Lib.Js Conformance

CriterionLevel
CKClient MUST implement anonymous-first connectionREQUIRED
CKClient MUST include all specified NATS headers on every messageREQUIRED
Control data MUST reside in headers, not in body payloadsREQUIRED
Token refresh MUST occur automatically before expiryREQUIRED
CKClient MUST handle NATS reconnection transparentlyREQUIRED
CKPage MUST load from CK.Lib.Js on the CK volume, not from CDN at runtimeREQUIRED

Released under the MIT License.