conceptkernel 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- conceptkernel-1.0.0/LICENSE +21 -0
- conceptkernel-1.0.0/PKG-INFO +195 -0
- conceptkernel-1.0.0/README.md +171 -0
- conceptkernel-1.0.0/cklib/__init__.py +29 -0
- conceptkernel-1.0.0/cklib/actions.py +277 -0
- conceptkernel-1.0.0/cklib/auth.py +98 -0
- conceptkernel-1.0.0/cklib/dispatch.py +179 -0
- conceptkernel-1.0.0/cklib/entities.py +95 -0
- conceptkernel-1.0.0/cklib/events.py +43 -0
- conceptkernel-1.0.0/cklib/execution.py +249 -0
- conceptkernel-1.0.0/cklib/instance.py +241 -0
- conceptkernel-1.0.0/cklib/ledger.py +216 -0
- conceptkernel-1.0.0/cklib/processor.py +237 -0
- conceptkernel-1.0.0/cklib/prov.py +631 -0
- conceptkernel-1.0.0/cklib/serve.py +254 -0
- conceptkernel-1.0.0/cklib/urn.py +466 -0
- conceptkernel-1.0.0/conceptkernel.egg-info/PKG-INFO +195 -0
- conceptkernel-1.0.0/conceptkernel.egg-info/SOURCES.txt +22 -0
- conceptkernel-1.0.0/conceptkernel.egg-info/dependency_links.txt +1 -0
- conceptkernel-1.0.0/conceptkernel.egg-info/requires.txt +13 -0
- conceptkernel-1.0.0/conceptkernel.egg-info/top_level.txt +1 -0
- conceptkernel-1.0.0/pyproject.toml +28 -0
- conceptkernel-1.0.0/setup.cfg +4 -0
- conceptkernel-1.0.0/tests/test_execution.py +132 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ConceptKernel.org
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: conceptkernel
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: CKP v3.5 Python runtime — kernel processor, provenance, execution proofs
|
|
5
|
+
Author-email: Peter Styk <peter@conceptkernel.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://conceptkernel.org
|
|
8
|
+
Project-URL: Repository, https://github.com/ConceptKernel/CK.Lib.Py
|
|
9
|
+
Project-URL: Ontology, https://conceptkernel.org/ontology/v3.5-alpha6/
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Provides-Extra: serve
|
|
14
|
+
Requires-Dist: fastapi>=0.100; extra == "serve"
|
|
15
|
+
Requires-Dist: uvicorn>=0.23; extra == "serve"
|
|
16
|
+
Requires-Dist: pyjwt>=2.8; extra == "serve"
|
|
17
|
+
Requires-Dist: httpx>=0.25; extra == "serve"
|
|
18
|
+
Requires-Dist: cryptography>=41.0; extra == "serve"
|
|
19
|
+
Provides-Extra: nats
|
|
20
|
+
Requires-Dist: nats-py>=2.6; extra == "nats"
|
|
21
|
+
Provides-Extra: yaml
|
|
22
|
+
Requires-Dist: pyyaml>=6.0; extra == "yaml"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# CK.Lib.Py — CKP v3.5 Python Runtime
|
|
26
|
+
|
|
27
|
+
Python runtime for the [Concept Kernel Protocol](https://conceptkernel.org) (CKP v3.5).
|
|
28
|
+
|
|
29
|
+
## What This Is
|
|
30
|
+
|
|
31
|
+
Every Concept Kernel that runs Python uses CK.Lib.Py. It provides:
|
|
32
|
+
- Base processor class that reads `conceptkernel.yaml` and dispatches NATS messages to `@on` handlers
|
|
33
|
+
- Instance lifecycle (create, seal, proof) following the three-loop model
|
|
34
|
+
- PROV-O provenance recording for every action
|
|
35
|
+
- Action composition via edge predicates (COMPOSES/EXTENDS/TRIGGERS)
|
|
36
|
+
- RBAC grants checking against `conceptkernel.yaml` grants block
|
|
37
|
+
- URN parsing, validation, and building per CKP URN scheme
|
|
38
|
+
|
|
39
|
+
## Architecture — Where Things Run
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
CLUSTER / LOCAL MACHINE (Python, nats-py) BROWSER / MOBILE (JS, nats.ws)
|
|
43
|
+
───────────────────────────────────────── ──────────────────────────────────
|
|
44
|
+
CK.Lib.Py CK.Lib.Js
|
|
45
|
+
KernelProcessor CKClient (ck-client.js)
|
|
46
|
+
NatsKernelLoop (nats-py) NATS WSS (nats.ws)
|
|
47
|
+
instance.py (writes to storage/) CKPage (ck-page.js)
|
|
48
|
+
prov.py (PROV-O chains) CKBus (ck-bus.js)
|
|
49
|
+
actions.py (edge composition) CKRegistry (ck-registry.js)
|
|
50
|
+
│ │
|
|
51
|
+
│ NATS (nats:// or wss://) │ NATS WSS only
|
|
52
|
+
│ Subject: input.{KernelName} │ Subject: input.{KernelName}
|
|
53
|
+
└──────────────── NATS SERVER ───────────────────┘
|
|
54
|
+
wss://stream.tech.games
|
|
55
|
+
JWT auth via Keycloak
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Python kernels** run on the cluster or local machine. They connect to NATS via `nats-py` (native TCP or WSS). They have filesystem access to their `storage/` directory. They write instances, proofs, and ledger entries.
|
|
59
|
+
|
|
60
|
+
**JavaScript clients** run in the browser or CLI. They connect to NATS via `nats.ws` (WebSocket only). They have NO filesystem access. They send action messages and receive results. They are `ckp:InlineKernel` / `ckp:NATSBrowserClient` per the published ontology.
|
|
61
|
+
|
|
62
|
+
**Messages are identical** regardless of sender. A `{ "action": "scout.scan" }` published to `input.Delvinator.ThreadScout` produces the same result whether it came from a Python kernel, a JS browser, or `delvinator.sh`.
|
|
63
|
+
|
|
64
|
+
## Ontology Grounding
|
|
65
|
+
|
|
66
|
+
**Published ontology:** https://conceptkernel.org/ontology/v3.5-alpha6/
|
|
67
|
+
|
|
68
|
+
| CK.Lib.Py concept | Published class | Module |
|
|
69
|
+
|-------------------|----------------|--------|
|
|
70
|
+
| `KernelProcessor` | `ckp:Kernel` (bfo:MaterialEntity + cco:Agent) | core.ttl |
|
|
71
|
+
| `@on("action")` handler | `ckp:Action` (iao:PlanSpecification) | core.ttl |
|
|
72
|
+
| `create_instance()` | `ckp:InstanceManifest` (iao:DataItem) | base-instances.ttl |
|
|
73
|
+
| `seal_instance()` | `ckp:SealedInstance` | base-instances.ttl |
|
|
74
|
+
| `append_ledger()` | `ckp:LedgerEntry` | base-instances.ttl |
|
|
75
|
+
| proof.json generation | `ckp:ProofRecord` + `ckp:ProofCheck` | proof.ttl |
|
|
76
|
+
| `ProvChain` sessions | `prov:Activity` chain | proof.ttl + PROV-O |
|
|
77
|
+
| Edge composition | `ckp:Edge` + `ckp:RelationshipType` | core.ttl |
|
|
78
|
+
| Grants/RBAC | rbac.ttl agents, roles, permissions | rbac.ttl |
|
|
79
|
+
| `NatsKernelLoop` | `ckp:NATSListening` (ServingDisposition) | kernel-metadata.ttl |
|
|
80
|
+
| URN scheme | CKP URN pattern (17 entity types) | core.ttl |
|
|
81
|
+
|
|
82
|
+
**Published ontology modules (all live at alpha-6 endpoint):**
|
|
83
|
+
|
|
84
|
+
| Module | URL | What it defines |
|
|
85
|
+
|--------|-----|-----------------|
|
|
86
|
+
| core.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/core.ttl) | Kernel, Edge, Instance, Action, Project, GovernanceMode |
|
|
87
|
+
| base-instances.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/base-instances.ttl) | InstanceManifest, SealedInstance, LedgerEntry |
|
|
88
|
+
| proof.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/proof.ttl) | ProofRecord, ProofCheck, CheckType |
|
|
89
|
+
| kernel-metadata.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/kernel-metadata.ttl) | ServingDisposition (NATSListening, NATSBrowserClient, WebServing, APIServing), StorageMedium, DeploymentMethod |
|
|
90
|
+
| processes.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/processes.ttl) | Invocation, EdgeCommunication, Consensus |
|
|
91
|
+
| relations.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/relations.ttl) | Edge properties, belongsToProject, hasKernel |
|
|
92
|
+
| rbac.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/rbac.ttl) | Authorization: agents, roles, permissions, quorum |
|
|
93
|
+
| workflow.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/workflow.ttl) | Workflow execution patterns |
|
|
94
|
+
| self-improvement.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/self-improvement.ttl) | Validation, recommendations, governance roles |
|
|
95
|
+
| shapes.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/shapes.ttl) | SHACL validation shapes |
|
|
96
|
+
|
|
97
|
+
## Modules
|
|
98
|
+
|
|
99
|
+
| Module | What it does | Key functions/classes |
|
|
100
|
+
|--------|-------------|---------------------|
|
|
101
|
+
| `processor.py` | Base class for all kernel processors. Reads `conceptkernel.yaml`, dispatches via `@on`, CLI args (`--status`, `--listen`, `--serve`, `--action`) | `KernelProcessor`, `KernelProcessor.run()` |
|
|
102
|
+
| `events.py` | Action handler decorator and typed event emission | `@on("action.name")`, `emit("EventType", **kwargs)` |
|
|
103
|
+
| `instance.py` | Instance lifecycle following the three-loop DATA pattern. Creates `storage/instances/i-{id}/` with manifest.json, seals with data.json, generates proof.json (SHA-256) | `create_instance()`, `seal_instance()`, `append_ledger()` |
|
|
104
|
+
| `execution.py` | Multi-step execution proofs with hash chains. Each step's input/output is SHA-256 hashed and chained to the previous step | `hash_step()`, `build_execution_proof()`, `seal_execution()`, `verify_chain()` |
|
|
105
|
+
| `prov.py` | PROV-O session recording. Every action in a session produces an `ActionRecord` with URNs linking Action → Instance → Task → Goal | `ProvChain`, `Session`, `ActionRecord`, `verified_action()` |
|
|
106
|
+
| `actions.py` | Action type resolution (`inspect`, `check`, `mutate`, `operate`, `query`, `deploy`, `transfer`). RBAC grants checking. Edge composition (COMPOSES/EXTENDS materialization) | `resolve_action_type()`, `check_access()`, `resolve_composed_actions()`, `get_effective_actions()` |
|
|
107
|
+
| `dispatch.py` | Local inter-kernel action dispatch and FIFO queue. For cluster/local — bypasses NATS for direct invocation | `send_action()`, `queue_action()`, `run_queue()` |
|
|
108
|
+
| `serve.py` | FastAPI HTTP server wrapping `@on` handlers. Token auth via Keycloak JWT or API key | `KernelServer` |
|
|
109
|
+
| `auth.py` | Keycloak JWT verification + API token fallback | `CKAuth` |
|
|
110
|
+
| `entities.py` | In-memory entity store with code-based lookup (for kernels that manage named entities) | `EntityManager` |
|
|
111
|
+
| `urn.py` | CKP URN parser, validator, builder. 17 entity types. Fleet-wide validation | `parse_urn()`, `validate_urn()`, `build_urn()`, `validate_fleet()` |
|
|
112
|
+
|
|
113
|
+
## The Three-Loop Contract
|
|
114
|
+
|
|
115
|
+
CK.Lib.Py enforces the CKP three-loop separation:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
CK LOOP (identity — read by KernelProcessor.__init__)
|
|
119
|
+
│ conceptkernel.yaml → self.identity, self.name, self.urn
|
|
120
|
+
│ ontology.yaml → defines what instances look like (the TYPE)
|
|
121
|
+
│ rules.shacl → validation constraints
|
|
122
|
+
│ CLAUDE.md, SKILL.md → for Claude Code agents
|
|
123
|
+
│
|
|
124
|
+
│ KernelProcessor READS these. It NEVER WRITES them.
|
|
125
|
+
│ Tool loop cannot modify CK loop — enforced by code structure.
|
|
126
|
+
│
|
|
127
|
+
TOOL LOOP (execution — this is where processor.py runs)
|
|
128
|
+
│ @on("action") handlers process input and return dicts
|
|
129
|
+
│ The handler NEVER opens storage/ for writing
|
|
130
|
+
│ It returns data; NatsKernelLoop handles storage writes
|
|
131
|
+
│
|
|
132
|
+
DATA LOOP (results — written by NatsKernelLoop or instance.py)
|
|
133
|
+
storage/instances/i-{trace}-{ts}/
|
|
134
|
+
manifest.json ← create_instance()
|
|
135
|
+
data.json ← seal_instance()
|
|
136
|
+
proof.json ← seal_instance() generates proof
|
|
137
|
+
ledger.json ← append_ledger()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## How a Kernel Processor Works
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from cklib import KernelProcessor, on, emit
|
|
144
|
+
|
|
145
|
+
class MyKernel(KernelProcessor):
|
|
146
|
+
"""Processor reads conceptkernel.yaml on init.
|
|
147
|
+
Exposes @on handlers that match spec.actions.
|
|
148
|
+
Returns dicts — never writes to storage directly."""
|
|
149
|
+
|
|
150
|
+
@on("my.action")
|
|
151
|
+
def handle(self, data):
|
|
152
|
+
# data = the message body from NATS or CLI
|
|
153
|
+
# Process...
|
|
154
|
+
result = {"answer": 42}
|
|
155
|
+
# Return typed event — NatsKernelLoop writes the instance
|
|
156
|
+
return emit("ActionCompleted", result=result)
|
|
157
|
+
|
|
158
|
+
if __name__ == "__main__":
|
|
159
|
+
MyKernel.run()
|
|
160
|
+
# CLI: python processor.py --status
|
|
161
|
+
# python processor.py --action my.action --data '{"key": "value"}'
|
|
162
|
+
# python processor.py --listen (NATS subscriber mode)
|
|
163
|
+
# python processor.py --serve (HTTP API mode)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## NATS Processing Cycle
|
|
167
|
+
|
|
168
|
+
When `--listen` is invoked, `NatsKernelLoop` (from `nats_kernel.py`) runs:
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
1. Connect to NATS WSS (wss://stream.tech.games)
|
|
172
|
+
2. Subscribe to input.{KernelName}
|
|
173
|
+
3. For each message:
|
|
174
|
+
a. Parse headers (Trace-Id, X-Kernel-ID, X-User-ID)
|
|
175
|
+
b. Parse body as JSON
|
|
176
|
+
c. Dispatch to handle_message() → @on handler
|
|
177
|
+
d. Write instance to storage/instances/i-{trace}-{ts}/message.json
|
|
178
|
+
e. Publish result to result.{KernelName}
|
|
179
|
+
f. Publish event to event.{KernelName} (type: "instance_created")
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Instance creation happens INSIDE the NATS loop — the handler just returns data. This is the three-loop isolation: tool returns, platform writes.
|
|
183
|
+
|
|
184
|
+
## Related Repositories
|
|
185
|
+
|
|
186
|
+
| Repo | Purpose | URL |
|
|
187
|
+
|------|---------|-----|
|
|
188
|
+
| **CK.Lib.Js** | JavaScript/browser client — CKPage, NATS WSS, web components | [ConceptKernel/CK.Lib.Js](https://github.com/ConceptKernel/CK.Lib.Js) |
|
|
189
|
+
| **CK.ComplianceCheck** | Fleet validation — 20 CKP check types | [ConceptKernel/CK.ComplianceCheck](https://github.com/ConceptKernel/CK.ComplianceCheck) |
|
|
190
|
+
| **CK.Operator** | Platform reconciliation | [ConceptKernel/CK.Operator](https://github.com/ConceptKernel/CK.Operator) |
|
|
191
|
+
| **Ontology** | Published CKP v3.5-alpha6 (10 Turtle modules) | [conceptkernel.org/ontology/v3.5-alpha6/](https://conceptkernel.org/ontology/v3.5-alpha6/) |
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# CK.Lib.Py — CKP v3.5 Python Runtime
|
|
2
|
+
|
|
3
|
+
Python runtime for the [Concept Kernel Protocol](https://conceptkernel.org) (CKP v3.5).
|
|
4
|
+
|
|
5
|
+
## What This Is
|
|
6
|
+
|
|
7
|
+
Every Concept Kernel that runs Python uses CK.Lib.Py. It provides:
|
|
8
|
+
- Base processor class that reads `conceptkernel.yaml` and dispatches NATS messages to `@on` handlers
|
|
9
|
+
- Instance lifecycle (create, seal, proof) following the three-loop model
|
|
10
|
+
- PROV-O provenance recording for every action
|
|
11
|
+
- Action composition via edge predicates (COMPOSES/EXTENDS/TRIGGERS)
|
|
12
|
+
- RBAC grants checking against `conceptkernel.yaml` grants block
|
|
13
|
+
- URN parsing, validation, and building per CKP URN scheme
|
|
14
|
+
|
|
15
|
+
## Architecture — Where Things Run
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
CLUSTER / LOCAL MACHINE (Python, nats-py) BROWSER / MOBILE (JS, nats.ws)
|
|
19
|
+
───────────────────────────────────────── ──────────────────────────────────
|
|
20
|
+
CK.Lib.Py CK.Lib.Js
|
|
21
|
+
KernelProcessor CKClient (ck-client.js)
|
|
22
|
+
NatsKernelLoop (nats-py) NATS WSS (nats.ws)
|
|
23
|
+
instance.py (writes to storage/) CKPage (ck-page.js)
|
|
24
|
+
prov.py (PROV-O chains) CKBus (ck-bus.js)
|
|
25
|
+
actions.py (edge composition) CKRegistry (ck-registry.js)
|
|
26
|
+
│ │
|
|
27
|
+
│ NATS (nats:// or wss://) │ NATS WSS only
|
|
28
|
+
│ Subject: input.{KernelName} │ Subject: input.{KernelName}
|
|
29
|
+
└──────────────── NATS SERVER ───────────────────┘
|
|
30
|
+
wss://stream.tech.games
|
|
31
|
+
JWT auth via Keycloak
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Python kernels** run on the cluster or local machine. They connect to NATS via `nats-py` (native TCP or WSS). They have filesystem access to their `storage/` directory. They write instances, proofs, and ledger entries.
|
|
35
|
+
|
|
36
|
+
**JavaScript clients** run in the browser or CLI. They connect to NATS via `nats.ws` (WebSocket only). They have NO filesystem access. They send action messages and receive results. They are `ckp:InlineKernel` / `ckp:NATSBrowserClient` per the published ontology.
|
|
37
|
+
|
|
38
|
+
**Messages are identical** regardless of sender. A `{ "action": "scout.scan" }` published to `input.Delvinator.ThreadScout` produces the same result whether it came from a Python kernel, a JS browser, or `delvinator.sh`.
|
|
39
|
+
|
|
40
|
+
## Ontology Grounding
|
|
41
|
+
|
|
42
|
+
**Published ontology:** https://conceptkernel.org/ontology/v3.5-alpha6/
|
|
43
|
+
|
|
44
|
+
| CK.Lib.Py concept | Published class | Module |
|
|
45
|
+
|-------------------|----------------|--------|
|
|
46
|
+
| `KernelProcessor` | `ckp:Kernel` (bfo:MaterialEntity + cco:Agent) | core.ttl |
|
|
47
|
+
| `@on("action")` handler | `ckp:Action` (iao:PlanSpecification) | core.ttl |
|
|
48
|
+
| `create_instance()` | `ckp:InstanceManifest` (iao:DataItem) | base-instances.ttl |
|
|
49
|
+
| `seal_instance()` | `ckp:SealedInstance` | base-instances.ttl |
|
|
50
|
+
| `append_ledger()` | `ckp:LedgerEntry` | base-instances.ttl |
|
|
51
|
+
| proof.json generation | `ckp:ProofRecord` + `ckp:ProofCheck` | proof.ttl |
|
|
52
|
+
| `ProvChain` sessions | `prov:Activity` chain | proof.ttl + PROV-O |
|
|
53
|
+
| Edge composition | `ckp:Edge` + `ckp:RelationshipType` | core.ttl |
|
|
54
|
+
| Grants/RBAC | rbac.ttl agents, roles, permissions | rbac.ttl |
|
|
55
|
+
| `NatsKernelLoop` | `ckp:NATSListening` (ServingDisposition) | kernel-metadata.ttl |
|
|
56
|
+
| URN scheme | CKP URN pattern (17 entity types) | core.ttl |
|
|
57
|
+
|
|
58
|
+
**Published ontology modules (all live at alpha-6 endpoint):**
|
|
59
|
+
|
|
60
|
+
| Module | URL | What it defines |
|
|
61
|
+
|--------|-----|-----------------|
|
|
62
|
+
| core.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/core.ttl) | Kernel, Edge, Instance, Action, Project, GovernanceMode |
|
|
63
|
+
| base-instances.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/base-instances.ttl) | InstanceManifest, SealedInstance, LedgerEntry |
|
|
64
|
+
| proof.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/proof.ttl) | ProofRecord, ProofCheck, CheckType |
|
|
65
|
+
| kernel-metadata.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/kernel-metadata.ttl) | ServingDisposition (NATSListening, NATSBrowserClient, WebServing, APIServing), StorageMedium, DeploymentMethod |
|
|
66
|
+
| processes.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/processes.ttl) | Invocation, EdgeCommunication, Consensus |
|
|
67
|
+
| relations.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/relations.ttl) | Edge properties, belongsToProject, hasKernel |
|
|
68
|
+
| rbac.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/rbac.ttl) | Authorization: agents, roles, permissions, quorum |
|
|
69
|
+
| workflow.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/workflow.ttl) | Workflow execution patterns |
|
|
70
|
+
| self-improvement.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/self-improvement.ttl) | Validation, recommendations, governance roles |
|
|
71
|
+
| shapes.ttl | [link](https://conceptkernel.org/ontology/v3.5-alpha6/shapes.ttl) | SHACL validation shapes |
|
|
72
|
+
|
|
73
|
+
## Modules
|
|
74
|
+
|
|
75
|
+
| Module | What it does | Key functions/classes |
|
|
76
|
+
|--------|-------------|---------------------|
|
|
77
|
+
| `processor.py` | Base class for all kernel processors. Reads `conceptkernel.yaml`, dispatches via `@on`, CLI args (`--status`, `--listen`, `--serve`, `--action`) | `KernelProcessor`, `KernelProcessor.run()` |
|
|
78
|
+
| `events.py` | Action handler decorator and typed event emission | `@on("action.name")`, `emit("EventType", **kwargs)` |
|
|
79
|
+
| `instance.py` | Instance lifecycle following the three-loop DATA pattern. Creates `storage/instances/i-{id}/` with manifest.json, seals with data.json, generates proof.json (SHA-256) | `create_instance()`, `seal_instance()`, `append_ledger()` |
|
|
80
|
+
| `execution.py` | Multi-step execution proofs with hash chains. Each step's input/output is SHA-256 hashed and chained to the previous step | `hash_step()`, `build_execution_proof()`, `seal_execution()`, `verify_chain()` |
|
|
81
|
+
| `prov.py` | PROV-O session recording. Every action in a session produces an `ActionRecord` with URNs linking Action → Instance → Task → Goal | `ProvChain`, `Session`, `ActionRecord`, `verified_action()` |
|
|
82
|
+
| `actions.py` | Action type resolution (`inspect`, `check`, `mutate`, `operate`, `query`, `deploy`, `transfer`). RBAC grants checking. Edge composition (COMPOSES/EXTENDS materialization) | `resolve_action_type()`, `check_access()`, `resolve_composed_actions()`, `get_effective_actions()` |
|
|
83
|
+
| `dispatch.py` | Local inter-kernel action dispatch and FIFO queue. For cluster/local — bypasses NATS for direct invocation | `send_action()`, `queue_action()`, `run_queue()` |
|
|
84
|
+
| `serve.py` | FastAPI HTTP server wrapping `@on` handlers. Token auth via Keycloak JWT or API key | `KernelServer` |
|
|
85
|
+
| `auth.py` | Keycloak JWT verification + API token fallback | `CKAuth` |
|
|
86
|
+
| `entities.py` | In-memory entity store with code-based lookup (for kernels that manage named entities) | `EntityManager` |
|
|
87
|
+
| `urn.py` | CKP URN parser, validator, builder. 17 entity types. Fleet-wide validation | `parse_urn()`, `validate_urn()`, `build_urn()`, `validate_fleet()` |
|
|
88
|
+
|
|
89
|
+
## The Three-Loop Contract
|
|
90
|
+
|
|
91
|
+
CK.Lib.Py enforces the CKP three-loop separation:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
CK LOOP (identity — read by KernelProcessor.__init__)
|
|
95
|
+
│ conceptkernel.yaml → self.identity, self.name, self.urn
|
|
96
|
+
│ ontology.yaml → defines what instances look like (the TYPE)
|
|
97
|
+
│ rules.shacl → validation constraints
|
|
98
|
+
│ CLAUDE.md, SKILL.md → for Claude Code agents
|
|
99
|
+
│
|
|
100
|
+
│ KernelProcessor READS these. It NEVER WRITES them.
|
|
101
|
+
│ Tool loop cannot modify CK loop — enforced by code structure.
|
|
102
|
+
│
|
|
103
|
+
TOOL LOOP (execution — this is where processor.py runs)
|
|
104
|
+
│ @on("action") handlers process input and return dicts
|
|
105
|
+
│ The handler NEVER opens storage/ for writing
|
|
106
|
+
│ It returns data; NatsKernelLoop handles storage writes
|
|
107
|
+
│
|
|
108
|
+
DATA LOOP (results — written by NatsKernelLoop or instance.py)
|
|
109
|
+
storage/instances/i-{trace}-{ts}/
|
|
110
|
+
manifest.json ← create_instance()
|
|
111
|
+
data.json ← seal_instance()
|
|
112
|
+
proof.json ← seal_instance() generates proof
|
|
113
|
+
ledger.json ← append_ledger()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## How a Kernel Processor Works
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from cklib import KernelProcessor, on, emit
|
|
120
|
+
|
|
121
|
+
class MyKernel(KernelProcessor):
|
|
122
|
+
"""Processor reads conceptkernel.yaml on init.
|
|
123
|
+
Exposes @on handlers that match spec.actions.
|
|
124
|
+
Returns dicts — never writes to storage directly."""
|
|
125
|
+
|
|
126
|
+
@on("my.action")
|
|
127
|
+
def handle(self, data):
|
|
128
|
+
# data = the message body from NATS or CLI
|
|
129
|
+
# Process...
|
|
130
|
+
result = {"answer": 42}
|
|
131
|
+
# Return typed event — NatsKernelLoop writes the instance
|
|
132
|
+
return emit("ActionCompleted", result=result)
|
|
133
|
+
|
|
134
|
+
if __name__ == "__main__":
|
|
135
|
+
MyKernel.run()
|
|
136
|
+
# CLI: python processor.py --status
|
|
137
|
+
# python processor.py --action my.action --data '{"key": "value"}'
|
|
138
|
+
# python processor.py --listen (NATS subscriber mode)
|
|
139
|
+
# python processor.py --serve (HTTP API mode)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## NATS Processing Cycle
|
|
143
|
+
|
|
144
|
+
When `--listen` is invoked, `NatsKernelLoop` (from `nats_kernel.py`) runs:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
1. Connect to NATS WSS (wss://stream.tech.games)
|
|
148
|
+
2. Subscribe to input.{KernelName}
|
|
149
|
+
3. For each message:
|
|
150
|
+
a. Parse headers (Trace-Id, X-Kernel-ID, X-User-ID)
|
|
151
|
+
b. Parse body as JSON
|
|
152
|
+
c. Dispatch to handle_message() → @on handler
|
|
153
|
+
d. Write instance to storage/instances/i-{trace}-{ts}/message.json
|
|
154
|
+
e. Publish result to result.{KernelName}
|
|
155
|
+
f. Publish event to event.{KernelName} (type: "instance_created")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Instance creation happens INSIDE the NATS loop — the handler just returns data. This is the three-loop isolation: tool returns, platform writes.
|
|
159
|
+
|
|
160
|
+
## Related Repositories
|
|
161
|
+
|
|
162
|
+
| Repo | Purpose | URL |
|
|
163
|
+
|------|---------|-----|
|
|
164
|
+
| **CK.Lib.Js** | JavaScript/browser client — CKPage, NATS WSS, web components | [ConceptKernel/CK.Lib.Js](https://github.com/ConceptKernel/CK.Lib.Js) |
|
|
165
|
+
| **CK.ComplianceCheck** | Fleet validation — 20 CKP check types | [ConceptKernel/CK.ComplianceCheck](https://github.com/ConceptKernel/CK.ComplianceCheck) |
|
|
166
|
+
| **CK.Operator** | Platform reconciliation | [ConceptKernel/CK.Operator](https://github.com/ConceptKernel/CK.Operator) |
|
|
167
|
+
| **Ontology** | Published CKP v3.5-alpha6 (10 Turtle modules) | [conceptkernel.org/ontology/v3.5-alpha6/](https://conceptkernel.org/ontology/v3.5-alpha6/) |
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
MIT
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""cklib — CKP v3.5 Python runtime for Concept Kernels.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
from cklib import KernelProcessor, on, emit
|
|
5
|
+
from cklib.urn import parse_urn, validate_urn, build_urn
|
|
6
|
+
from cklib.instance import create_instance, seal_instance
|
|
7
|
+
from cklib.dispatch import send_action
|
|
8
|
+
from cklib.serve import KernelServer
|
|
9
|
+
from cklib.auth import CKAuth
|
|
10
|
+
from cklib.entities import EntityManager
|
|
11
|
+
from cklib.actions import resolve_action_type, check_access
|
|
12
|
+
from cklib.prov import ProvChain, Session, ActionRecord, verified_action, list_sessions, get_session
|
|
13
|
+
from cklib.ledger import log_action, read_ledger
|
|
14
|
+
"""
|
|
15
|
+
from cklib.processor import KernelProcessor
|
|
16
|
+
from cklib.events import on, emit
|
|
17
|
+
from cklib.entities import EntityManager
|
|
18
|
+
from cklib.actions import resolve_action_type, check_access
|
|
19
|
+
from cklib.prov import ProvChain, Session, ActionRecord, verified_action, list_sessions, get_session
|
|
20
|
+
from cklib.ledger import log_action, read_ledger
|
|
21
|
+
|
|
22
|
+
__version__ = "1.0.0"
|
|
23
|
+
__all__ = [
|
|
24
|
+
"KernelProcessor", "on", "emit", "EntityManager",
|
|
25
|
+
"resolve_action_type", "check_access",
|
|
26
|
+
"ProvChain", "Session", "ActionRecord", "verified_action",
|
|
27
|
+
"list_sessions", "get_session",
|
|
28
|
+
"log_action", "read_ledger",
|
|
29
|
+
]
|