omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / omega_library.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef OMEGA_LIBRARY_H |
| 18 | #define OMEGA_LIBRARY_H |
| 19 | |
| 20 | #include "omega_program.h" |
| 21 | #include "omega_synthesis.h" |
| 22 | #include <stdbool.h> |
| 23 | #include <stddef.h> |
| 24 | |
| 25 | #define OMEGA_LIB_MAX_PROGRAMS 128 |
| 26 | #define OMEGA_LIB_MAX_DEPS 32 |
| 27 | |
| 28 | /* How an entry was admitted. Part of the state digest, so a bootstrap entry and a verified |
| 29 | * entry with identical bytes never share a digest. 0 is never a valid kind. */ |
| 30 | #define OMEGA_LIB_ADMISSION_VERIFIED 1u /* omega_library_insert: verified + receipt */ |
| 31 | #define OMEGA_LIB_ADMISSION_BOOTSTRAP 2u /* omega_library_insert_bootstrap: genesis set only */ |
| 32 | |
| 33 | typedef struct { |
| 34 | OmegaProgram program; |
| 35 | uint32_t version_introduced; |
| 36 | uint64_t timestamp_added; |
| 37 | size_t dep_count; |
| 38 | SemanticId dependency_ids[OMEGA_LIB_MAX_DEPS]; |
| 39 | uint8_t evidence_receipt_hash[32]; /* verified: receipt hash; bootstrap: audit hash */ |
| 40 | uint8_t admission_kind; /* OMEGA_LIB_ADMISSION_* */ |
| 41 | } OmegaLibraryEntry; |
| 42 | |
| 43 | typedef struct { |
| 44 | uint32_t version; |
| 45 | size_t count; |
| 46 | OmegaLibraryEntry entries[OMEGA_LIB_MAX_PROGRAMS]; |
| 47 | uint8_t state_digest[32]; |
| 48 | } OmegaLibrary; |
| 49 | |
| 50 | /* Initialize empty library at version 1 */ |
| 51 | int omega_library_init(OmegaLibrary *lib); |
| 52 | |
| 53 | /* Free all resources owned by the library */ |
| 54 | void omega_library_destroy(OmegaLibrary *lib); |
| 55 | |
| 56 | /* Insert a verified program into the library (admission kind VERIFIED). |
| 57 | * Returns -1 and leaves the library unchanged if: |
| 58 | * - lib or prog is NULL, or prog is not verified and realized |
| 59 | * - receipt_hash is NULL or all zero (a verified admission needs evidence) |
| 60 | * - prog has no identity (all-zero program_id) |
| 61 | * - duplicate SemanticId already exists |
| 62 | * - capacity exceeded |
| 63 | * - dep_count > OMEGA_LIB_MAX_DEPS (never truncated), or deps is NULL with dep_count > 0 |
| 64 | * - any dependency id is not already in the library |
| 65 | * - dependency cycle detected |
| 66 | */ |
| 67 | int omega_library_insert(OmegaLibrary *lib, const OmegaProgram *prog, |
| 68 | const SemanticId *deps, size_t dep_count, |
| 69 | const uint8_t receipt_hash[32]); |
| 70 | |
| 71 | /* Insert one program of the manually audited GENESIS set (admission kind BOOTSTRAP). |
| 72 | * Same refusals as omega_library_insert, with audit_hash (NULL or all zero refused) in |
| 73 | * place of the receipt hash. |
| 74 | * |
| 75 | * MUST NEVER be called outside genesis loading. There is no runtime flag, environment |
| 76 | * variable or build option that unlocks it: reviewers must reject any caller that is not |
| 77 | * the genesis loader (VC1 stage 6). The admission kind is recorded in the entry and in the |
| 78 | * state digest, so bootstrap entries are always distinguishable from verified ones. */ |
| 79 | int omega_library_insert_bootstrap(OmegaLibrary *lib, const OmegaProgram *prog, |
| 80 | const SemanticId *deps, size_t dep_count, |
| 81 | const uint8_t audit_hash[32]); |
| 82 | |
| 83 | /* Content-addressed lookup by program SemanticId */ |
| 84 | const OmegaLibraryEntry* omega_library_find_by_id(const OmegaLibrary *lib, const SemanticId *prog_id); |
| 85 | |
| 86 | /* Content-addressed lookup by realization SemanticId */ |
| 87 | const OmegaLibraryEntry* omega_library_find_by_realization_id(const OmegaLibrary *lib, const SemanticId *real_id); |
| 88 | |
| 89 | /* Lookup by human-readable name */ |
| 90 | const OmegaLibraryEntry* omega_library_find_by_name(const OmegaLibrary *lib, const char *name); |
| 91 | |
| 92 | /* Semantic query: find all programs matching input/output types and widths */ |
| 93 | size_t omega_library_query_by_type(const OmegaLibrary *lib, |
| 94 | TypeTag in_type, uint16_t in_width, |
| 95 | TypeTag out_type, uint16_t out_width, |
| 96 | const OmegaLibraryEntry **out_results, size_t max_results); |
| 97 | |
| 98 | /* Compute cryptographic checksum over entire library state */ |
| 99 | int omega_library_compute_digest(OmegaLibrary *lib); |
| 100 | |
| 101 | /* Advance version and seal state digest */ |
| 102 | int omega_library_advance_version(OmegaLibrary *lib); |
| 103 | |
| 104 | /* Cycle detection across library dependencies */ |
| 105 | bool omega_library_has_cycle(const OmegaLibrary *lib, const SemanticId *target_id, |
| 106 | const SemanticId *new_deps, size_t new_dep_count); |
| 107 | |
| 108 | /* Export library programs into a synthesis primitive bank for abstraction reuse */ |
| 109 | int omega_library_export_primitives(const OmegaLibrary *lib, SynthPrimitiveBank *bank); |
| 110 | |
| 111 | #endif /* OMEGA_LIBRARY_H */ |