clm-kernel 0.0.0__py3-none-any.whl
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.
- clm/__init__.py +230 -0
- clm/__main__.py +25 -0
- clm/cross_cutting/__init__.py +50 -0
- clm/cross_cutting/_test_runner.py +36 -0
- clm/cross_cutting/async_utils.py +25 -0
- clm/cross_cutting/cel_builder.py +123 -0
- clm/cross_cutting/cel_converter.py +697 -0
- clm/cross_cutting/cel_engine.py +252 -0
- clm/cross_cutting/cel_ops.py +72 -0
- clm/cross_cutting/cel_ops_db.py +157 -0
- clm/cross_cutting/cel_ops_files.py +99 -0
- clm/cross_cutting/cel_ops_state.py +71 -0
- clm/cross_cutting/cel_ops_strings.py +64 -0
- clm/cross_cutting/cel_resolver.py +63 -0
- clm/cross_cutting/cel_slices.py +56 -0
- clm/cross_cutting/cel_store.py +330 -0
- clm/cross_cutting/clm_logger.py +140 -0
- clm/cross_cutting/config/__init__.py +155 -0
- clm/cross_cutting/config/config_constants.py +392 -0
- clm/cross_cutting/config/env_parameters.py +90 -0
- clm/cross_cutting/config/logging.py +378 -0
- clm/cross_cutting/config/settings.py +504 -0
- clm/cross_cutting/context.py +5 -0
- clm/cross_cutting/domain_models.py +55 -0
- clm/cross_cutting/domain_types.py +61 -0
- clm/cross_cutting/effects.py +67 -0
- clm/cross_cutting/errors.py +153 -0
- clm/cross_cutting/governance.py +331 -0
- clm/cross_cutting/guards.py +41 -0
- clm/cross_cutting/mcard.py +321 -0
- clm/cross_cutting/native.py +185 -0
- clm/cross_cutting/observability.py +289 -0
- clm/cross_cutting/pcard.py +434 -0
- clm/cross_cutting/registry.py +71 -0
- clm/cross_cutting/resources.py +84 -0
- clm/cross_cutting/secrets.py +44 -0
- clm/cross_cutting/subprocess_utils.py +118 -0
- clm/cross_cutting/telemetry.py +164 -0
- clm/cross_cutting/testing/__init__.py +8 -0
- clm/cross_cutting/testing/comparator.py +187 -0
- clm/cross_cutting/testing/datasets.py +87 -0
- clm/cross_cutting/timeutil.py +20 -0
- clm/cross_cutting/types/new_type_check.py +0 -0
- clm/cross_cutting/utils/__init__.py +1 -0
- clm/cross_cutting/utils/url_safety.py +50 -0
- clm/cross_cutting/vcard.py +560 -0
- clm/cross_cutting/writer.py +118 -0
- clm/layer0/README.md +50 -0
- clm/layer0/__init__.py +223 -0
- clm/layer0/algebra.py +60 -0
- clm/layer0/algebra_baldwin.py +133 -0
- clm/layer0/algebra_baldwin_generators.py +36 -0
- clm/layer0/algebra_equivalence.py +262 -0
- clm/layer0/algebra_ingest.py +306 -0
- clm/layer0/algebra_manifest_io.py +156 -0
- clm/layer0/assembler.py +481 -0
- clm/layer0/cel/__init__.py +23 -0
- clm/layer0/cel_eval.py +491 -0
- clm/layer0/codec.py +106 -0
- clm/layer0/context.py +122 -0
- clm/layer0/db.py +160 -0
- clm/layer0/exceptions.py +73 -0
- clm/layer0/fibration.py +106 -0
- clm/layer0/gates.py +50 -0
- clm/layer0/hash.py +80 -0
- clm/layer0/loader.py +826 -0
- clm/layer0/math_utils.py +163 -0
- clm/layer0/mcard.py +96 -0
- clm/layer0/model/__init__.py +0 -0
- clm/layer0/model/action.py +223 -0
- clm/layer0/model/card.py +280 -0
- clm/layer0/model/card_triad.py +427 -0
- clm/layer0/model/compatibility.py +60 -0
- clm/layer0/model/dictionary.py +46 -0
- clm/layer0/model/dots.py +331 -0
- clm/layer0/model/event_producer.py +88 -0
- clm/layer0/model/g_time.py +89 -0
- clm/layer0/model/handle.py +163 -0
- clm/layer0/model/hash/__init__.py +6 -0
- clm/layer0/model/hash/algorithms/__init__.py +3 -0
- clm/layer0/model/hash/algorithms/custom_hash.py +7 -0
- clm/layer0/model/hash/algorithms/local_sha256.py +178 -0
- clm/layer0/model/hash/constants.py +53 -0
- clm/layer0/model/hash/enums.py +60 -0
- clm/layer0/model/hash/validator.py +307 -0
- clm/layer0/model/interpreter.py +275 -0
- clm/layer0/model/pagination.py +45 -0
- clm/layer0/model/pcard.py +716 -0
- clm/layer0/model/schema.py +44 -0
- clm/layer0/model/utils/__init__.py +1 -0
- clm/layer0/model/utils/content_analyzer.py +152 -0
- clm/layer0/model/validators/__init__.py +1 -0
- clm/layer0/model/validators/base_validator.py +44 -0
- clm/layer0/model/validators/binary_validator.py +66 -0
- clm/layer0/model/validators/text_validator.py +82 -0
- clm/layer0/model/validators/validation_registry.py +49 -0
- clm/layer0/model/vcard.py +823 -0
- clm/layer0/model/vcard_ext/__init__.py +39 -0
- clm/layer0/model/vcard_ext/core.py +60 -0
- clm/layer0/model/vcard_ext/network.py +23 -0
- clm/layer0/model/vcard_ext/observability.py +63 -0
- clm/layer0/model/vcard_ext/storage.py +60 -0
- clm/layer0/model/vcard_ext/vendors.py +211 -0
- clm/layer0/model/vcard_sandwich.py +119 -0
- clm/layer0/model/vcard_vocabulary.py +463 -0
- clm/layer0/model/workflow.py +274 -0
- clm/layer0/narrative.py +431 -0
- clm/layer0/ontology/collection.py +125 -0
- clm/layer0/parser.py +429 -0
- clm/layer0/relations.py +73 -0
- clm/layer0/rule_evaluator.py +251 -0
- clm/layer0/schema/__init__.py +38 -0
- clm/layer0/schema/ddl.py +97 -0
- clm/layer0/templates/abstract.yaml +99 -0
- clm/layer0/templates/balanced.yaml +253 -0
- clm/layer0/templates/concrete.yaml +172 -0
- clm/layer0/type_registry.py +223 -0
- clm/layer0/types.py +204 -0
- clm/layer0/utils.py +886 -0
- clm/layer0/verifier_core.py +262 -0
- clm/layer1/__init__.py +31 -0
- clm/layer1/action_dispatcher.py +275 -0
- clm/layer1/adapter_registry.py +233 -0
- clm/layer1/algebra_baldwin_generators.py +192 -0
- clm/layer1/arrow_compiler.py +525 -0
- clm/layer1/batch_processor.py +152 -0
- clm/layer1/cel/__init__.py +27 -0
- clm/layer1/cel/builder.py +173 -0
- clm/layer1/engine.py +759 -0
- clm/layer1/engine_async.py +89 -0
- clm/layer1/eval_callback.py +49 -0
- clm/layer1/gate_composer.py +229 -0
- clm/layer1/hoare_sandwich.py +298 -0
- clm/layer1/identity_guard.py +348 -0
- clm/layer1/matrix.py +138 -0
- clm/layer1/neural_runtime.py +221 -0
- clm/layer1/operations/__init__.py +123 -0
- clm/layer1/operations/augment.py +156 -0
- clm/layer1/operations/base.py +109 -0
- clm/layer1/operations/builtins.py +338 -0
- clm/layer1/operations/dispatch.py +144 -0
- clm/layer1/operations/exclude.py +107 -0
- clm/layer1/operations/handle.py +197 -0
- clm/layer1/operations/identity.py +139 -0
- clm/layer1/operations/invert.py +66 -0
- clm/layer1/operations/loader.py +116 -0
- clm/layer1/operations/manipulators/__init__.py +23 -0
- clm/layer1/operations/manipulators/document.py +211 -0
- clm/layer1/operations/manipulators/media.py +134 -0
- clm/layer1/operations/manipulators/structured.py +159 -0
- clm/layer1/operations/manipulators/tabular.py +334 -0
- clm/layer1/operations/port.py +65 -0
- clm/layer1/operations/services.py +529 -0
- clm/layer1/operations/split.py +117 -0
- clm/layer1/operations/substitute.py +75 -0
- clm/layer1/petri.py +1052 -0
- clm/layer1/pocketflow_orchestrator.py +408 -0
- clm/layer1/pocketflow_scheduler.py +519 -0
- clm/layer1/protocols.py +197 -0
- clm/layer1/runtime_adapter.py +718 -0
- clm/layer1/runtimes/__init__.py +71 -0
- clm/layer1/runtimes/_generated_assertions.py +125 -0
- clm/layer1/runtimes/_generated_types.py +42 -0
- clm/layer1/runtimes/base.py +265 -0
- clm/layer1/runtimes/binary.py +101 -0
- clm/layer1/runtimes/factory.py +203 -0
- clm/layer1/runtimes/javascript.py +321 -0
- clm/layer1/runtimes/javascript_runtime.js +33 -0
- clm/layer1/runtimes/js_scripts/isomorphism.mjs +22 -0
- clm/layer1/runtimes/js_scripts/loader.mjs +52 -0
- clm/layer1/runtimes/lambda_calc.py +126 -0
- clm/layer1/runtimes/python.py +288 -0
- clm/layer1/runtimes/python_runtime.py +41 -0
- clm/layer1/runtimes/script.py +114 -0
- clm/layer1/sandbox.py +334 -0
- clm/layer1/savepoint_guard.py +136 -0
- clm/layer1/sparse_net.py +122 -0
- clm/layer1/spec_tester.py +165 -0
- clm/layer1/store.py +295 -0
- clm/layer1/test_runner.py +498 -0
- clm/layer1/type_inspector.py +166 -0
- clm/layer1/verifier.py +772 -0
- clm/layer1/vm.py +91 -0
- clm/layer2/__init__.py +78 -0
- clm/layer2/card_collection.py +678 -0
- clm/layer2/classifier.py +479 -0
- clm/layer2/engine/__init__.py +1 -0
- clm/layer2/engine/abstract_sql_engine.py +320 -0
- clm/layer2/engine/base.py +193 -0
- clm/layer2/engine/duckdb_engine.py +576 -0
- clm/layer2/engine/sqlite_engine.py +518 -0
- clm/layer2/fiber/__init__.py +31 -0
- clm/layer2/fiber/context.py +89 -0
- clm/layer2/fiber/disposable.py +163 -0
- clm/layer2/fiber/fiber.py +125 -0
- clm/layer2/fiber/hoare.py +191 -0
- clm/layer2/file_io.py +376 -0
- clm/layer2/file_registrar.py +77 -0
- clm/layer2/ingest.py +202 -0
- clm/layer2/lineage.py +322 -0
- clm/layer2/mcard_fs.py +262 -0
- clm/layer2/merkle.py +11 -0
- clm/layer2/mime.py +244 -0
- clm/layer2/mime_detector.py +245 -0
- clm/layer2/private_collection.py +118 -0
- clm/layer2/shared_store.py +11 -0
- clm/layer2/storage/__init__.py +190 -0
- clm/layer2/storage/db_bitemporal.py +141 -0
- clm/layer2/storage/db_driver.py +331 -0
- clm/layer2/storage/db_hyperlinks.py +214 -0
- clm/layer2/storage/db_pool.py +139 -0
- clm/layer2/storage/db_repository.py +229 -0
- clm/layer2/storage/savepoint.py +78 -0
- clm/layer2/storage/sqlite_wal.py +74 -0
- clm/layer2/tridb.py +245 -0
- clm/layer2/vcard_receipt.py +71 -0
- clm/layer2/vfs.py +17 -0
- clm/layer3/__init__.py +141 -0
- clm/layer3/agency/__init__.py +19 -0
- clm/layer3/agency/config.py +220 -0
- clm/layer3/agency/providers/__init__.py +15 -0
- clm/layer3/agency/providers/base.py +91 -0
- clm/layer3/agency/providers/mlc_llm.py +169 -0
- clm/layer3/agency/providers/ollama.py +203 -0
- clm/layer3/agency/router.py +71 -0
- clm/layer3/agency/runtime.py +524 -0
- clm/layer3/gateway.py +353 -0
- clm/layer3/open_interpreter_adapter.py +159 -0
- clm/layer3/rag/__init__.py +70 -0
- clm/layer3/rag/cli.py +228 -0
- clm/layer3/rag/config.py +153 -0
- clm/layer3/rag/embeddings/__init__.py +16 -0
- clm/layer3/rag/embeddings/base.py +79 -0
- clm/layer3/rag/embeddings/ollama.py +211 -0
- clm/layer3/rag/embeddings/vision.py +290 -0
- clm/layer3/rag/engine.py +276 -0
- clm/layer3/rag/graph/__init__.py +22 -0
- clm/layer3/rag/graph/community.py +198 -0
- clm/layer3/rag/graph/engine.py +433 -0
- clm/layer3/rag/graph/extractor.py +255 -0
- clm/layer3/rag/graph/schema.py +115 -0
- clm/layer3/rag/graph/store.py +641 -0
- clm/layer3/rag/indexer.py +333 -0
- clm/layer3/rag/llm_providers.json +52 -0
- clm/layer3/rag/semantic_versioning.py +313 -0
- clm/layer3/rag/vector/__init__.py +28 -0
- clm/layer3/rag/vector/handle_vector_store.py +749 -0
- clm/layer3/rag/vector/schema.py +151 -0
- clm/layer3/rag/vector/store.py +632 -0
- clm/layer3/reticulum/__init__.py +55 -0
- clm/layer3/reticulum/bridge.py +74 -0
- clm/layer3/reticulum/daemon.py +88 -0
- clm/layer3/reticulum/discovery.py +164 -0
- clm/layer3/reticulum/identity.py +107 -0
- clm/layer3/reticulum/media.py +148 -0
- clm/layer3/reticulum/transport.py +133 -0
- clm/layer3/satori/__init__.py +209 -0
- clm/layer3/satori/alpha_conversion.py +168 -0
- clm/layer3/satori/beta_reduction.py +359 -0
- clm/layer3/satori/continuation.py +38 -0
- clm/layer3/satori/eta_conversion.py +205 -0
- clm/layer3/satori/free_variables.py +163 -0
- clm/layer3/satori/io_effects.py +370 -0
- clm/layer3/satori/lambda_runtime.py +726 -0
- clm/layer3/satori/lambda_term.py +230 -0
- clm/layer3/satori/sheaf_audit.py +261 -0
- clm/layer3/satori/speech_act.py +279 -0
- clm/layer4/README.md +9 -0
- clm/layer4/__init__.py +67 -0
- clm/layer4/_sovereign_executor.py +580 -0
- clm/layer4/action_commands.py +719 -0
- clm/layer4/api.py +236 -0
- clm/layer4/bootstrap/__init__.py +13 -0
- clm/layer4/bootstrap/bootstrapper.py +118 -0
- clm/layer4/bootstrap/cleanup.py +44 -0
- clm/layer4/bootstrap/clm_hooks.py +49 -0
- clm/layer4/bootstrap/genesis.py +77 -0
- clm/layer4/bootstrap/injection.py +125 -0
- clm/layer4/cli.py +549 -0
- clm/layer4/collection_manager.py +553 -0
- clm/layer4/commands/__init__.py +81 -0
- clm/layer4/commands/action_cmd.py +42 -0
- clm/layer4/commands/check_cmd.py +82 -0
- clm/layer4/commands/envelope.py +73 -0
- clm/layer4/commands/evaluate_cmd.py +224 -0
- clm/layer4/commands/mcard_cmd.py +24 -0
- clm/layer4/commands/petri_cmd.py +92 -0
- clm/layer4/commands/tridb_cmd.py +319 -0
- clm/layer4/commands/version_cmd.py +27 -0
- clm/layer4/diff_commands.py +167 -0
- clm/layer4/eoa_sponsor.py +232 -0
- clm/layer4/events.py +69 -0
- clm/layer4/flux_gateway.py +133 -0
- clm/layer4/gateway.py +91 -0
- clm/layer4/loader.py +307 -0
- clm/layer4/mcard_commands.py +166 -0
- clm/layer4/membrane.py +273 -0
- clm/layer4/navigation.py +50 -0
- clm/layer4/protocol/protocol_entry_python.py +108 -0
- clm/layer4/protocol/python_sync.py +126 -0
- clm/layer4/runner.py +150 -0
- clm/layer4/satori.py +262 -0
- clm/layer4/server/python_sync_client.py +150 -0
- clm/layer4/server/python_sync_server.py +139 -0
- clm/layer4/server/service_api.py +315 -0
- clm/layer4/server/start_servers.py +107 -0
- clm/layer4/server/stop_servers.py +24 -0
- clm/layer4/simulated_optimization_fix.py +0 -0
- clm/layer4/storage.py +463 -0
- clm/layer4/tridb_admin.py +268 -0
- clm/layer4/websocket/test_ws_client.py +104 -0
- clm/layer4/websocket/test_ws_server.py +138 -0
- clm/layer4/websocket/ws_server_local.py +160 -0
- clm/layer5/__init__.py +51 -0
- clm/layer5/async_batch_writer.py +133 -0
- clm/layer5/learning.py +276 -0
- clm/layer5/telemetry_hook.py +107 -0
- clm/layer5/type_lattice.py +238 -0
- clm/py.typed +0 -0
- clm/schemas/__init__.py +652 -0
- clm/schemas/abstract_face_schema.yaml +77 -0
- clm/schemas/cel_schema.yaml +416 -0
- clm/schemas/lifecycle/__init__.py +45 -0
- clm/schemas/lifecycle/models.py +123 -0
- clm/schemas/lifecycle/service.py +364 -0
- clm/schemas/mcard_schema.sql +192 -0
- clm/schemas/mcard_vector_schema.sql +283 -0
- clm/schemas/mlp-context-v1.json +91 -0
- clm_kernel-0.0.0.dist-info/METADATA +121 -0
- clm_kernel-0.0.0.dist-info/RECORD +333 -0
- clm_kernel-0.0.0.dist-info/WHEEL +4 -0
- clm_kernel-0.0.0.dist-info/entry_points.txt +3 -0
- clm_kernel-0.0.0.dist-info/licenses/LICENSE +21 -0
clm/layer0/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# CLM Layer 0: Algebraic Baldwin Modularity Operators
|
|
2
|
+
|
|
3
|
+
## Mathematical Foundations & Lattice Generator Dynamics
|
|
4
|
+
|
|
5
|
+
The CLM interpretation pipeline formalizes design evolution and architectural transformations through Carliss Baldwin and Kim Clark's six modularity operators ("Design Rules: The Power of Modularity"). In CLM, each operator acts as a native lattice generator over Coloured Petri Nets (CPNs) and Arrow Categories $\mathbf{Arr}(\mathbf{C})$.
|
|
6
|
+
|
|
7
|
+
### 1. Split Operator ($\sigma$)
|
|
8
|
+
- **Formal Definition**: Decomposes a monolithic arrow $A: X \to Y$ into parallel, orthogonal sub-arrows $B: X \to Y_1$ and $C: X \to Y_2$, recombining their outputs via product pairing:
|
|
9
|
+
$$\sigma(A, B, C) = A \gg (B \times C)$$
|
|
10
|
+
- **Algebraic Laws**:
|
|
11
|
+
- **Functorial Factorization**: $\sigma(A, B, C)$ preserves typing $X \to Y_1 \times Y_2$.
|
|
12
|
+
- **Token Conservation**: Incidence matrix column sum invariance: $\sum_{i} D_{i, j} = 0 \quad \forall j \in \mathcal{T}$.
|
|
13
|
+
- **Product Commutativity**: $\sigma(A, B, C) \cong \tau \circ \sigma(A, C, B)$ where $\tau(y_1, y_2) = (y_2, y_1)$ is swap.
|
|
14
|
+
|
|
15
|
+
### 2. Augment Operator ($\alpha$)
|
|
16
|
+
- **Formal Definition**: Additively composes an extension arrow $E: Y \to Z$ onto an existing CPN net $\mathcal{N}_A$:
|
|
17
|
+
$$\alpha(\mathcal{N}_A, E) = \mathcal{N}_A \gg \mathcal{N}_E$$
|
|
18
|
+
- **Algebraic Laws**:
|
|
19
|
+
- **Associativity**: $\alpha(\alpha(\mathcal{N}_A, E_1), E_2) \equiv \alpha(\mathcal{N}_A, E_1 \gg E_2)$.
|
|
20
|
+
- **Identity**: For identity arrow $\mathrm{id}$, $\alpha(\mathcal{N}_A, \mathrm{id}) \equiv \mathcal{N}_A$.
|
|
21
|
+
- **Token Conservation**: Inflow into $E$ equals outflow from $A$, conserving overall token balance.
|
|
22
|
+
|
|
23
|
+
### 3. Exclude Operator ($\epsilon$)
|
|
24
|
+
- **Formal Definition**: Prunes an internal arrow step $S_k$ from a composite pipeline $\mathcal{N} = S_1 \gg \dots \gg S_k \gg \dots \gg S_n$, producing a bypass net and an immutable audit descriptor $\mathcal{A}$:
|
|
25
|
+
$$\epsilon(\mathcal{N}, S_k) = (\mathcal{N} \setminus \{S_k\}, \mathcal{A}_{\epsilon}(S_k))$$
|
|
26
|
+
- **Algebraic Laws**:
|
|
27
|
+
- **Audit Immutability**: Every exclusion generates a cryptographic record containing timestamp, hash, and operator provenance.
|
|
28
|
+
- **Idempotence with Audit**: $\epsilon(\epsilon(\mathcal{N}, S_k), S_k) = \epsilon(\mathcal{N}, S_k)$.
|
|
29
|
+
|
|
30
|
+
### 4. Substitute Operator ($\rho$)
|
|
31
|
+
- **Formal Definition**: Hot-swaps an internal constituent arrow $S_k$ with an interface-compatible replacement arrow $S'_k$:
|
|
32
|
+
$$\rho(\mathcal{N}, S_k, S'_k) = \mathcal{N}[S_k \mapsto S'_k]$$
|
|
33
|
+
- **Algebraic Laws**:
|
|
34
|
+
- **Interface Invariance**: $\mathrm{dom}(S_k) = \mathrm{dom}(S'_k) \land \mathrm{cod}(S_k) = \mathrm{cod}(S'_k)$.
|
|
35
|
+
- **Homomorphic Replacement**: If $S'_k \sim S_k$ semantically, the external behavior of $\rho(\mathcal{N}, S_k, S'_k)$ preserves all boundary contracts.
|
|
36
|
+
- **Identity Replacement**: $\rho(\mathcal{N}, S_k, S_k) \equiv \mathcal{N}$.
|
|
37
|
+
|
|
38
|
+
### 5. Invert Operator ($\iota$)
|
|
39
|
+
- **Formal Definition**: Reverses coordinate tuples or dualizes state space transitions:
|
|
40
|
+
$$\iota(A: X \to Y_1 \times Y_2) = A \gg \mathrm{swap}$$
|
|
41
|
+
- **Algebraic Laws**:
|
|
42
|
+
- **Involution**: $\iota(\iota(A)) \equiv A$.
|
|
43
|
+
- **Duality**: Inverting an incidence matrix transition flips prep/seal directional dynamics while maintaining state reachability.
|
|
44
|
+
|
|
45
|
+
### 6. Port Operator ($\pi$)
|
|
46
|
+
- **Formal Definition**: Translates an arrow module across different runtime execution environments (e.g., Python $\to$ TypeScript $\to$ WASM) using a standardized boundary adapter:
|
|
47
|
+
$$\pi(\mathcal{N}, R_{\mathrm{target}}) = \mathcal{A}_{\mathrm{in}} \gg \mathcal{N}_{R_{\mathrm{target}}} \gg \mathcal{A}_{\mathrm{out}}$$
|
|
48
|
+
- **Algebraic Laws**:
|
|
49
|
+
- **Target Parity**: $\forall x \in \mathrm{dom}(\mathcal{N}): \pi(\mathcal{N}, R_2)(\pi(\mathcal{N}, R_1)(x)) = \mathcal{N}(x)$.
|
|
50
|
+
- **Cross-Runtime Behavioral Equivalence**: Byte-level bit-identical assertion parity across polyglot targets under canonical inputs.
|
clm/layer0/__init__.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""CLM Layer 0 Kenotic Microkernel package (Sprint 387, DEL-387-07).
|
|
2
|
+
|
|
3
|
+
Provides pure algebraic primitives, AST parsers, codecs, hashing, and static schemas.
|
|
4
|
+
Heavy, I/O-bound, and storage subsystems are loaded lazily via __getattr__ to maintain
|
|
5
|
+
Kenotic Purity (INV-01, INV-09, INV-10) upon `import clm.layer0`.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from clm.layer0.assembler import (
|
|
13
|
+
AssembledCLM,
|
|
14
|
+
CLMAssembler,
|
|
15
|
+
CLMComponent,
|
|
16
|
+
ValidationResult,
|
|
17
|
+
)
|
|
18
|
+
from clm.layer0.codec import (
|
|
19
|
+
canonical_json,
|
|
20
|
+
canonical_yaml,
|
|
21
|
+
from_base58,
|
|
22
|
+
from_hex,
|
|
23
|
+
to_base58,
|
|
24
|
+
to_hex,
|
|
25
|
+
)
|
|
26
|
+
from clm.layer0.context import CLMContext
|
|
27
|
+
from clm.layer0.exceptions import (
|
|
28
|
+
AlgebraError,
|
|
29
|
+
CLMError,
|
|
30
|
+
DatabaseError,
|
|
31
|
+
ExecutionError,
|
|
32
|
+
GatewayError,
|
|
33
|
+
KenoticPurityViolationError,
|
|
34
|
+
TypeValidationError,
|
|
35
|
+
)
|
|
36
|
+
from clm.layer0.gates import (
|
|
37
|
+
GatePredicate,
|
|
38
|
+
evaluate_gate,
|
|
39
|
+
evaluate_gate_set,
|
|
40
|
+
)
|
|
41
|
+
from clm.layer0.hash import (
|
|
42
|
+
BLAKE3_PREFIX,
|
|
43
|
+
SHA256_PREFIX,
|
|
44
|
+
compute_blake3,
|
|
45
|
+
compute_sha256,
|
|
46
|
+
prefixed_hash,
|
|
47
|
+
verify_hash,
|
|
48
|
+
)
|
|
49
|
+
from clm.layer0.loader import (
|
|
50
|
+
CLMChapterLoader,
|
|
51
|
+
YAMLTemplateLoader,
|
|
52
|
+
)
|
|
53
|
+
from clm.layer0.math_utils import math_gcd, math_lcm, solve_nullspace
|
|
54
|
+
from clm.layer0.mcard import (
|
|
55
|
+
MCard,
|
|
56
|
+
MCardPayload,
|
|
57
|
+
create_mcard,
|
|
58
|
+
payload_to_bytes,
|
|
59
|
+
to_canonical_bytes,
|
|
60
|
+
verify_mcard_integrity,
|
|
61
|
+
)
|
|
62
|
+
from clm.layer0.narrative import (
|
|
63
|
+
Chapter,
|
|
64
|
+
CLMConfiguration,
|
|
65
|
+
NarrativeMonad,
|
|
66
|
+
)
|
|
67
|
+
from clm.layer0.parser import (
|
|
68
|
+
ClmRoot,
|
|
69
|
+
ParsedClmAst,
|
|
70
|
+
UnifiedClmParser,
|
|
71
|
+
)
|
|
72
|
+
from clm.layer0.type_registry import TypeRegistry, load_clm_features
|
|
73
|
+
from clm.layer0.types import (
|
|
74
|
+
ArchitecturalPlane,
|
|
75
|
+
CHLDimension,
|
|
76
|
+
CHLTemporal,
|
|
77
|
+
ExecutionResult,
|
|
78
|
+
LivenessMetric,
|
|
79
|
+
PolynomialTerm,
|
|
80
|
+
PostconditionViolation,
|
|
81
|
+
PreconditionViolation,
|
|
82
|
+
PrimeHash,
|
|
83
|
+
SafetyViolation,
|
|
84
|
+
TemporalPhase,
|
|
85
|
+
VerificationStatus,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Lazy export routing table to preserve import-time purity
|
|
89
|
+
_LAZY_EXPORTS: dict[str, str] = {
|
|
90
|
+
# algebra
|
|
91
|
+
"assess_equivalence_py": "clm.layer0.algebra",
|
|
92
|
+
"directory_fs_scan_py": "clm.layer0.algebra",
|
|
93
|
+
"directory_to_db_py": "clm.layer0.algebra",
|
|
94
|
+
"load_normalized_manifest": "clm.layer0.algebra",
|
|
95
|
+
# db (storage facade)
|
|
96
|
+
"CLMDB": "clm.layer0.db",
|
|
97
|
+
"CLMRepository": "clm.layer0.db",
|
|
98
|
+
"init_tridb": "clm.layer0.db",
|
|
99
|
+
"memorize_mcard": "clm.layer0.db",
|
|
100
|
+
"register_handle": "clm.layer0.db",
|
|
101
|
+
"resolve_handle_content": "clm.layer0.db",
|
|
102
|
+
"resolve_handle_hash": "clm.layer0.db",
|
|
103
|
+
# utils
|
|
104
|
+
"clm_hash_file": "clm.layer0.utils",
|
|
105
|
+
"clm_hash_string": "clm.layer0.utils",
|
|
106
|
+
"detect_host_os": "clm.layer0.utils",
|
|
107
|
+
"extract_python_script_from_yaml": "clm.layer0.utils",
|
|
108
|
+
"get_bash_command": "clm.layer0.utils",
|
|
109
|
+
"is_docker_live": "clm.layer0.utils",
|
|
110
|
+
"normalize_line_endings_bytes": "clm.layer0.utils",
|
|
111
|
+
"normalize_line_endings_str": "clm.layer0.utils",
|
|
112
|
+
"resolve_clm_path": "clm.layer0.utils",
|
|
113
|
+
"verify_file_hash": "clm.layer0.utils",
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def __getattr__(name: str) -> Any:
|
|
118
|
+
target_mod = _LAZY_EXPORTS.get(name)
|
|
119
|
+
if target_mod:
|
|
120
|
+
mod = sys.modules.get(target_mod)
|
|
121
|
+
if mod is None:
|
|
122
|
+
__import__(target_mod)
|
|
123
|
+
mod = sys.modules.get(target_mod)
|
|
124
|
+
if mod is not None and hasattr(mod, name):
|
|
125
|
+
return getattr(mod, name)
|
|
126
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
__all__ = [
|
|
130
|
+
# exceptions
|
|
131
|
+
"CLMError",
|
|
132
|
+
"TypeValidationError",
|
|
133
|
+
"DatabaseError",
|
|
134
|
+
"ExecutionError",
|
|
135
|
+
"AlgebraError",
|
|
136
|
+
"GatewayError",
|
|
137
|
+
"KenoticPurityViolationError",
|
|
138
|
+
# utils (lazy)
|
|
139
|
+
"resolve_clm_path",
|
|
140
|
+
"clm_hash_file",
|
|
141
|
+
"clm_hash_string",
|
|
142
|
+
"detect_host_os",
|
|
143
|
+
"is_docker_live",
|
|
144
|
+
"get_bash_command",
|
|
145
|
+
"normalize_line_endings_bytes",
|
|
146
|
+
"normalize_line_endings_str",
|
|
147
|
+
"verify_file_hash",
|
|
148
|
+
"extract_python_script_from_yaml",
|
|
149
|
+
# db (lazy)
|
|
150
|
+
"CLMDB",
|
|
151
|
+
"CLMRepository",
|
|
152
|
+
"init_tridb",
|
|
153
|
+
"memorize_mcard",
|
|
154
|
+
"resolve_handle_content",
|
|
155
|
+
"resolve_handle_hash",
|
|
156
|
+
"register_handle",
|
|
157
|
+
# math & context
|
|
158
|
+
"math_gcd",
|
|
159
|
+
"math_lcm",
|
|
160
|
+
"solve_nullspace",
|
|
161
|
+
"TypeRegistry",
|
|
162
|
+
"load_clm_features",
|
|
163
|
+
"CLMContext",
|
|
164
|
+
# algebra (lazy)
|
|
165
|
+
"load_normalized_manifest",
|
|
166
|
+
"assess_equivalence_py",
|
|
167
|
+
"directory_fs_scan_py",
|
|
168
|
+
"directory_to_db_py",
|
|
169
|
+
# hash
|
|
170
|
+
"compute_blake3",
|
|
171
|
+
"compute_sha256",
|
|
172
|
+
"prefixed_hash",
|
|
173
|
+
"verify_hash",
|
|
174
|
+
"BLAKE3_PREFIX",
|
|
175
|
+
"SHA256_PREFIX",
|
|
176
|
+
# codec
|
|
177
|
+
"to_hex",
|
|
178
|
+
"from_hex",
|
|
179
|
+
"to_base58",
|
|
180
|
+
"from_base58",
|
|
181
|
+
"canonical_json",
|
|
182
|
+
"canonical_yaml",
|
|
183
|
+
# mcard
|
|
184
|
+
"MCard",
|
|
185
|
+
"MCardPayload",
|
|
186
|
+
"payload_to_bytes",
|
|
187
|
+
"create_mcard",
|
|
188
|
+
"verify_mcard_integrity",
|
|
189
|
+
"to_canonical_bytes",
|
|
190
|
+
# gates
|
|
191
|
+
"GatePredicate",
|
|
192
|
+
"evaluate_gate",
|
|
193
|
+
"evaluate_gate_set",
|
|
194
|
+
# parser
|
|
195
|
+
"UnifiedClmParser",
|
|
196
|
+
"ParsedClmAst",
|
|
197
|
+
"ClmRoot",
|
|
198
|
+
# narrative
|
|
199
|
+
"Chapter",
|
|
200
|
+
"NarrativeMonad",
|
|
201
|
+
"CLMConfiguration",
|
|
202
|
+
# loader
|
|
203
|
+
"CLMChapterLoader",
|
|
204
|
+
"YAMLTemplateLoader",
|
|
205
|
+
# assembler
|
|
206
|
+
"CLMAssembler",
|
|
207
|
+
"AssembledCLM",
|
|
208
|
+
"CLMComponent",
|
|
209
|
+
"ValidationResult",
|
|
210
|
+
# types
|
|
211
|
+
"PrimeHash",
|
|
212
|
+
"PolynomialTerm",
|
|
213
|
+
"SafetyViolation",
|
|
214
|
+
"LivenessMetric",
|
|
215
|
+
"VerificationStatus",
|
|
216
|
+
"ExecutionResult",
|
|
217
|
+
"CHLDimension",
|
|
218
|
+
"TemporalPhase",
|
|
219
|
+
"CHLTemporal",
|
|
220
|
+
"ArchitecturalPlane",
|
|
221
|
+
"PreconditionViolation",
|
|
222
|
+
"PostconditionViolation",
|
|
223
|
+
]
|
clm/layer0/algebra.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Layer 0 — Baldwin Algebra and Equivalence Assessment (Sprint 133.1 shim).
|
|
2
|
+
|
|
3
|
+
Sprint 133.1 decomposed this 896-line god-module into four sibling modules:
|
|
4
|
+
- ``algebra_manifest_io.py`` — manifest loading, hashing, PCard execution, value canonicalization
|
|
5
|
+
- ``algebra_equivalence.py`` — Homotopy Equivalence Gate (assess_equivalence_py)
|
|
6
|
+
- ``algebra_ingest.py`` — directory scanning and DB ingestion (Function-Number Duality bridge)
|
|
7
|
+
- ``algebra_baldwin.py`` — Baldwin Exclude operator
|
|
8
|
+
|
|
9
|
+
This file remains as a thin re-export shim for backward compatibility.
|
|
10
|
+
Full shim removal deferred to Sprint 134.
|
|
11
|
+
"""
|
|
12
|
+
from clm.cross_cutting.clm_logger import get_logger
|
|
13
|
+
|
|
14
|
+
from .algebra_baldwin import exclude_clm_py
|
|
15
|
+
from .algebra_equivalence import _ANSI_RE, _find_divergence, _normalize_output, assess_equivalence_py
|
|
16
|
+
from .algebra_ingest import _storage_fallback_warn_or_fail, directory_fs_scan_py, directory_to_db_py
|
|
17
|
+
from .algebra_manifest_io import (
|
|
18
|
+
canonical_value_py,
|
|
19
|
+
check_content_equivalent_py,
|
|
20
|
+
clean_data_py,
|
|
21
|
+
compare_numerical_py,
|
|
22
|
+
compute_stripped_file_hash_py,
|
|
23
|
+
execute_pcard_py,
|
|
24
|
+
load_normalized_manifest,
|
|
25
|
+
load_normalized_manifest_str,
|
|
26
|
+
parse_json_or_yaml_py,
|
|
27
|
+
)
|
|
28
|
+
from .assembler import (
|
|
29
|
+
AssembledCLM,
|
|
30
|
+
CLMAssembler,
|
|
31
|
+
CLMComponent,
|
|
32
|
+
ValidationResult,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
_logger = get_logger("clm.algebra")
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"_ANSI_RE",
|
|
39
|
+
"_find_divergence",
|
|
40
|
+
"_normalize_output",
|
|
41
|
+
"_storage_fallback_warn_or_fail",
|
|
42
|
+
"assess_equivalence_py",
|
|
43
|
+
"canonical_value_py",
|
|
44
|
+
"check_content_equivalent_py",
|
|
45
|
+
"clean_data_py",
|
|
46
|
+
"compare_numerical_py",
|
|
47
|
+
"compute_stripped_file_hash_py",
|
|
48
|
+
"directory_fs_scan_py",
|
|
49
|
+
"directory_to_db_py",
|
|
50
|
+
"exclude_clm_py",
|
|
51
|
+
"execute_pcard_py",
|
|
52
|
+
"load_normalized_manifest",
|
|
53
|
+
"load_normalized_manifest_str",
|
|
54
|
+
"parse_json_or_yaml_py",
|
|
55
|
+
"AssembledCLM",
|
|
56
|
+
"CLMAssembler",
|
|
57
|
+
"CLMComponent",
|
|
58
|
+
"ValidationResult",
|
|
59
|
+
]
|
|
60
|
+
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Baldwin Exclude Operator (Sprint 133.1).
|
|
2
|
+
|
|
3
|
+
Extracted from ``algebra.py``. Python-native implementation of the Baldwin
|
|
4
|
+
Modularity Operator: Exclude. Prunes constraints/paths from a CLM manifest
|
|
5
|
+
and archives the excluded content as an audit trail.
|
|
6
|
+
"""
|
|
7
|
+
import contextlib
|
|
8
|
+
import os
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import yaml
|
|
12
|
+
|
|
13
|
+
from clm.layer0.utils import clm_hash_string
|
|
14
|
+
|
|
15
|
+
from .utils import resolve_clm_path
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def exclude_clm_py(clm_root: str, clm_file: str, exclude_path: str) -> tuple[int, str, str]:
|
|
19
|
+
"""
|
|
20
|
+
Python-native implementation of Baldwin Modularity Operator: Exclude.
|
|
21
|
+
Prunes constraints/paths from a CLM manifest and archives the excluded content as an audit trail.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
clm_root (str): The workspace root directory.
|
|
25
|
+
clm_file (str): The path to the CLM file to modify.
|
|
26
|
+
exclude_path (str): The dot-separated yq-style path to prune (e.g. '.clm.abstract.invariants').
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
Tuple[int, str, str]: (exit_code, stdout, stderr)
|
|
30
|
+
"""
|
|
31
|
+
clm_file = resolve_clm_path(clm_root, clm_file)
|
|
32
|
+
if not os.path.exists(clm_file):
|
|
33
|
+
return 1, "", f"Target file not found: {clm_file}"
|
|
34
|
+
|
|
35
|
+
# Load manifest
|
|
36
|
+
with open(clm_file, encoding='utf-8') as f:
|
|
37
|
+
try:
|
|
38
|
+
data = yaml.safe_load(f)
|
|
39
|
+
except Exception as e:
|
|
40
|
+
return 1, "", f"Failed to parse YAML manifest: {e}"
|
|
41
|
+
|
|
42
|
+
# Normalize exclude path format (strip leading dot if needed)
|
|
43
|
+
path_str = exclude_path.strip()
|
|
44
|
+
if path_str.startswith('.'):
|
|
45
|
+
path_str = path_str[1:]
|
|
46
|
+
parts = [p for p in path_str.split('.') if p]
|
|
47
|
+
|
|
48
|
+
# Helper to retrieve value by path
|
|
49
|
+
def get_by_path(d: Any, path_parts: list[str]) -> Any:
|
|
50
|
+
curr = d
|
|
51
|
+
for p in path_parts:
|
|
52
|
+
if isinstance(curr, dict) and p in curr:
|
|
53
|
+
curr = curr[p]
|
|
54
|
+
else:
|
|
55
|
+
return None
|
|
56
|
+
return curr
|
|
57
|
+
|
|
58
|
+
existing = get_by_path(data, parts)
|
|
59
|
+
if existing is None:
|
|
60
|
+
msg = f"[EXCLUDE] ⚠️ Path not found: {exclude_path} — nothing to exclude"
|
|
61
|
+
return 0, msg, ""
|
|
62
|
+
|
|
63
|
+
# Archive the excluded content as an Execution MCard (audit trail)
|
|
64
|
+
excluded_content = yaml.dump(existing, default_flow_style=False)
|
|
65
|
+
excl_hash = clm_hash_string(excluded_content)
|
|
66
|
+
|
|
67
|
+
from clm.layer0.verifier_core import emit_exec_mcard_py
|
|
68
|
+
indented_content = "\n".join(" " + line for line in excluded_content.splitlines())
|
|
69
|
+
extra_yaml = f"source_clm: \"{clm_file}\"\nexcluded_path: \"{exclude_path}\"\ncontent:\n{indented_content}"
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
audit_file = emit_exec_mcard_py(clm_root, "exclude", excl_hash, extra_yaml)
|
|
73
|
+
except Exception as e:
|
|
74
|
+
return 1, "", f"Failed to emit audit execution MCard: {e}"
|
|
75
|
+
|
|
76
|
+
# Calculate hash of original file to derive pruned file name
|
|
77
|
+
with open(clm_file, 'rb') as f:
|
|
78
|
+
orig_bytes = f.read()
|
|
79
|
+
pruned_hash = clm_hash_string(orig_bytes)
|
|
80
|
+
|
|
81
|
+
output_dir = os.path.join(clm_root, "data/content_memory")
|
|
82
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
83
|
+
pruned_file = os.path.join(output_dir, f"excluded_{pruned_hash[:12]}.yaml")
|
|
84
|
+
|
|
85
|
+
# Helper to delete key by path
|
|
86
|
+
def delete_by_path(d: Any, path_parts: list[str]) -> bool:
|
|
87
|
+
if not path_parts:
|
|
88
|
+
return False
|
|
89
|
+
curr = d
|
|
90
|
+
for p in path_parts[:-1]:
|
|
91
|
+
if isinstance(curr, dict) and p in curr:
|
|
92
|
+
curr = curr[p]
|
|
93
|
+
else:
|
|
94
|
+
return False
|
|
95
|
+
last_part = path_parts[-1]
|
|
96
|
+
if isinstance(curr, dict) and last_part in curr:
|
|
97
|
+
del curr[last_part]
|
|
98
|
+
return True
|
|
99
|
+
return False
|
|
100
|
+
|
|
101
|
+
# Perform the deletion
|
|
102
|
+
delete_by_path(data, parts)
|
|
103
|
+
|
|
104
|
+
# Write pruned content to file
|
|
105
|
+
with open(pruned_file, 'w', encoding='utf-8') as f:
|
|
106
|
+
yaml.dump(data, f, default_flow_style=False)
|
|
107
|
+
|
|
108
|
+
# Validate that pruned CLM still passes grammar in strict type mode
|
|
109
|
+
from clm.layer0.verifier_core import verify_precondition
|
|
110
|
+
orig_strict = os.environ.get("CLM_STRICT_TYPES")
|
|
111
|
+
os.environ["CLM_STRICT_TYPES"] = "true"
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
valid = verify_precondition(clm_root, pruned_file)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
valid = False
|
|
117
|
+
err_msg = str(e)
|
|
118
|
+
else:
|
|
119
|
+
err_msg = "Grammar validation failed"
|
|
120
|
+
finally:
|
|
121
|
+
if orig_strict is not None:
|
|
122
|
+
os.environ["CLM_STRICT_TYPES"] = orig_strict
|
|
123
|
+
else:
|
|
124
|
+
with contextlib.suppress(KeyError):
|
|
125
|
+
del os.environ["CLM_STRICT_TYPES"]
|
|
126
|
+
|
|
127
|
+
if not valid:
|
|
128
|
+
if os.path.exists(pruned_file):
|
|
129
|
+
os.remove(pruned_file)
|
|
130
|
+
return 1, "", f"Exclusion REJECTED — would produce invalid CLM: {err_msg}"
|
|
131
|
+
|
|
132
|
+
stdout_msg = f"Archived excluded content: {audit_file}\nExcluded CLM: {pruned_file}"
|
|
133
|
+
return 0, stdout_msg, ""
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Deprecated backward-compatibility shim for Baldwin CPN generators (INV-383-02).
|
|
2
|
+
|
|
3
|
+
Canonical path: clm.layer1.algebra_baldwin_generators
|
|
4
|
+
All new code should import from clm.layer1.algebra_baldwin_generators directly.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
import warnings
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
warnings.warn(
|
|
14
|
+
"clm.layer0.algebra_baldwin_generators is deprecated. "
|
|
15
|
+
"Import from clm.layer1.algebra_baldwin_generators instead.",
|
|
16
|
+
DeprecationWarning,
|
|
17
|
+
stacklevel=2,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"BaldwinAlgebraicError",
|
|
22
|
+
"BaldwinAuditRecord",
|
|
23
|
+
"BaldwinCpnGenerators",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def __getattr__(name: str) -> Any:
|
|
28
|
+
if name in __all__:
|
|
29
|
+
target = "clm.layer1.algebra_baldwin_generators"
|
|
30
|
+
mod = sys.modules.get(target)
|
|
31
|
+
if mod is None:
|
|
32
|
+
__import__(target)
|
|
33
|
+
mod = sys.modules.get(target)
|
|
34
|
+
if mod is not None:
|
|
35
|
+
return getattr(mod, name)
|
|
36
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|