YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
- COSMIC INVARIANT SIEVE
Β· β¦ Β·
Β· β¦ Β· β¦
β¦ Β· Β· β¦ Β· β¦ Β·
Β· β¦ Β· β¦ Β· β¦ Β· β¦ Β·
βββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββ
β±β² β±β² β±β² β±β² β±β²
β± β² β± β² β± β² β± β² β± β²
β±βββββ² β±βββββ² β±βββββ² β±βββββ² β±βββββ²
β± β¦ β² β± β² β± β² β± β² β± β¦ β²
β±βββββββββ³βββββββββ³βββββββββ³βββββββββ³βββββββββ²
β ββββββββββββββββββββββββββββββββββββββββββββ β
β β C O S M I C I N V A R I A N T β β
β β S I E V E β β
β ββββββββββββββββββββββββββββββββββββββββββββ β
β²βββββββββ±β²βββββββββ±β²βββββββββ±β²βββββββββ±β²βββββ±
β² β¦ β± β² β± β² β± β² β± β² β¦ β±
β²βββββ± β²βββββ± β²βββββ± β²βββββ± β²βββββ±
β² β± β² β± β² β± β² β± β² β±
β²β± β²β± β²β± β²β± β²β±
βββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββ
Β· β¦ Β· β¦ Β· β¦ Β· β¦ Β·
β¦ Β· Β· β¦ Β· β¦ Β·
Β· β¦ Β· β¦
Β· β¦ Β·
COSMIC INVARIANT SIEVE
Formal Verification + Sovereign Borrow Chain + Julia Execution
A compiler-shaped customs checkpoint for agent-generated code.
Every patch passes through mathematical proof, policy evaluation, structural analysis, and a hostile borrow-chain tripwire before producing a signed binary.
Live Repo Β· Architecture Β· Borrow Chain Β· Agent Policy
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLASSIFICATION: Sovereign Compute β Aerospace-Grade Verification β
β TRUST MODEL: 10-Gate Pipeline + Borrow-Chain Tripwire β
β PROOF ENGINE: Isabelle/HOL + ASP/Clingo + Julia + INTERCAL β
β POLICY: NO PROOF β NO SAT β NO BORROW CHAIN β NO BINARY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The Cosmic Theorem
Theorem (Cosmic Invariant Sieve Correctness). Let S be agent-generated source code. Let P be the set of formal invariants. Let V be the verification pipeline. Then:
V(S) = PASS βΉ S satisfies all invariants in P V(S) = FAIL βΉ S is quarantined and cannot produce a binaryProof sketch. The pipeline is a monotone consequence operator: each gate either preserves the invariant set or rejects. The INTERCAL tripwire encodes the borrow chain into a compiler-enforced checksum that cannot be bypassed. The receipt seals the exact proof path. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β THE SIEVE THEOREM β
β β
β β S β Source: β
β V(S) = PASS βΊ β§_{i=1}^{10} Gate_i(S) = PASS β
β β
β Where: β
β Gate 1: Parses into canonical IR β
β Gate 2: Mathematical invariants compile in Isabelle/HOL β
β Gate 3: All required invariant tokens are present β
β Gate 4: ASP/Clingo returns SATISFIABLE β
β Gate 5: Julia reports type stability β
β Gate 6: Julia reports valid ownership β
β Gate 7: Julia reports valid borrow scopes β
β Gate 8: Julia reports declared effects only β
β Gate 9: INTERCAL tripwire compiles and exits correctly β
β Gate 10: Julia native artifact matches source hash β
β β
β Failure at any gate: β
β freeze source β quarantine β emit receipt β block merge β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Architecture
LaTeX / source model / agent-generated code
β
βΌ
βββββββββββββββββββ
β CANONICAL IR β
β Normalized Form β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β ISABELLE/HOL β
β Mathematical β
β Proofs β
ββββββββββ¬βββββββββ
β
PROVED βββ΄ββ REJECTED
β β
βΌ βββ HARD STOP
βββββββββββββββββββ
β INVARIANT TOKENS β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β ASP / CLINGO β
β Closed-World β
β Policy Eval β
ββββββββββ¬βββββββββ
β
SAT ββββ΄βββ UNSAT
β β
βΌ βββ HARD STOP
βββββββββββββββββββββββ
β JULIA STRUCTURAL β
β ANALYZER β
β Type, Allocation, β
β Effect, Graph β
ββββββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β INTERCAL BORROW- β
β CHAIN TRIPWIRE β
β Adversarial β
β Structural Gate β
ββββββββββ¬βββββββββββββ
β
PASS βββ΄ββ FAIL
β β
βΌ βββ QUARANTINE
βββββββββββββββββββ
β JULIA NATIVE β
β COMPILATION β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β SIGNED BINARY β
β + PROOF RECEIPT β
βββββββββββββββββββ
Pipeline Stages
| Stage | Component | Input | Output | Gate |
|---|---|---|---|---|
| 10 | Normalize Source | Raw source | Canonical IR | Gate 1 |
| 20 | Isabelle/HOL | Canonical IR | Proof certificates | Gate 2 |
| 30 | Export Invariants | Proof certificates | Invariant tokens | Gate 3 |
| 40 | ASP/Clingo | Tokens + policies | SAT/UNSAT | Gate 4 |
| 50 | Julia Analysis | IR + tokens | Structural report | Gates 5-8 |
| 60 | Emit INTERCAL | Structural report | Tripwire source | β |
| 70 | Run Tripwire | INTERCAL source | PASS/FAIL | Gate 9 |
| 80 | Julia Compile | Verified IR | Native binary | Gate 10 |
| 90 | Seal Receipt | All outputs | Signed receipt | β |
Core Policy
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β NO PROOF β NO SAT β
β NO SAT β NO BORROW CHAIN β
β NO VALID BORROW β NO INTERCAL PASS β
β NO INTERCAL PASS β NO JULIA BINARY β
β NO RECEIPT β NO RELEASE β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Borrow Chain
Every generated value carries a governance record:
struct BorrowEvent
resource_id::UInt128
owner_id::UInt128
borrower_id::UInt128
mode::Symbol # :own, :shared, :exclusive, :moved, :released, :destroyed
scope_start::UInt64
scope_end::UInt64
mutable::Bool
effect_class::Symbol
dependency_parents::Vector{UInt128}
destruction_event::Union{Nothing,UInt128}
receipt_hash::String
end
Core Rules
1. One resource has one active owner.
2. Many shared borrows allowed only when no exclusive exists.
3. One exclusive borrow allowed only when no shared exists.
4. A moved resource cannot be read from the former owner.
5. A destroyed resource cannot be borrowed.
6. Borrow scopes must form a properly nested chain.
7. Cycles in ownership or effect dependencies are rejected.
8. Mutation must be explicitly authorized.
9. Every side effect must be declared before execution.
Append-Only Event Chain
GENESIS
β
RESOURCE_CREATED
β
OWNER_ASSIGNED
β
BORROW_OPENED
β
MUTATION_AUTHORIZED
β
BORROW_CLOSED
β
RESOURCE_MOVED
β
RESOURCE_DESTROYED
Every transition: h_k = SHA256(h_{k-1} β event_k)
Spaghetti-Code Detection
Reject generated code when it crosses thresholds for:
| Metric | Threshold | Description |
|---|---|---|
max_function_lines |
80 | Lines per function |
max_cyclomatic_complexity |
12 | Branching factor |
max_call_depth |
16 | Nesting depth |
max_module_fan_out |
8 | Dependencies outward |
max_mutation_sites |
6 | Mutation points |
max_dynamic_dispatch_sites |
0 | Dynamic dispatch |
max_allocations_per_hot_path |
4 | Heap allocations |
require_type_stability |
true | Must be type-stable |
Violation Classes
alias_violation β invalid SELECT mask
ownership_cycle β unresolved label dependency
use_after_move β missing resource array slot
hidden_mutation β etiquette imbalance marker
undeclared_effect β forbidden COME FROM edge
type_instability β invalid width transition
spaghetti β structural complexity overflow
Isabelle/HOL Theories
| Theory | Purpose |
|---|---|
Cosmic_Invariant_Sieve.thy |
Top-level entry: core types, ownership model, lifecycle operations |
Quantum_State.thy |
Quantum state types, gate operations, norm preservation |
Matrix_Operators.thy |
Matrix types, Hermitian/unitary predicates, trace properties |
Program_Invariants.thy |
Function declarations, effect kinds, complexity predicates |
Ownership_Model.thy |
Ownership records, mode transitions, graph acyclicity |
Borrow_Chain.thy |
Borrow events, scope nesting, conflict detection |
Effect_Safety.thy |
Effect declarations, policy compliance, authorization |
Token_Extraction.thy |
Invariant tokens, proof hashes, consistency predicates |
Key Theorems
theorem single_owner_invariant:
"β s rid. worm_sealed s βΆ single_owner_check s rid"
theorem borrow_preserves_owner:
"β s rid aid s'. borrow_shared s rid aid = Some s' βΆ ..."
theorem acquire_release_symmetry:
"β s rid aid s' s''. acquire_resource s rid aid = Some s' βΆ ..."
theorem scopes_nested_no_conflict:
"scopes_properly_nested chain βΆ no_conflicting_borrows chain"
ASP/Clingo Rules
| Rule File | Purpose |
|---|---|
cosmic_invariants.lp |
Top-level aggregation, SAT/UNSAT determination |
ownership_rules.lp |
Single-owner invariant enforcement |
borrow_rules.lp |
Borrow chain mode validation |
effect_rules.lp |
Effect declaration and safety |
dependency_rules.lp |
Module dependency cycle detection |
spaghetti_rules.lp |
Structural complexity rejection |
Julia Modules
| Module | Purpose |
|---|---|
CosmicSieve.jl |
Entry point: analyze_source, emit_tripwire, compile_verified |
CanonicalIR.jl |
Source parsing, hash computation, IR construction |
CodeGraph.jl |
Dependency graph building, cycle detection, fan-out/in |
Ownership.jl |
Single-owner validation, dual-ownership detection |
BorrowChain.jl |
Scope nesting, mode conflict, cycle detection |
EffectAnalysis.jl |
Forbidden effect detection, shell execution blocking |
AllocationAnalysis.jl |
Heap allocation budgeting per hot path |
TypeStability.jl |
Dynamic dispatch detection, type mismatch finding |
IntercalEmitter.jl |
INTERCAL source generation from violation reports |
NativeCompiler.jl |
Verified source compilation to native binary |
Receipts.jl |
Cryptographic receipt generation and sealing |
Analysis Output
{
"status": "STRUCTURALLY_VALID",
"type_stable": true,
"allocation_budget_passed": true,
"borrow_chain_valid": true,
"effect_policy_valid": true,
"dependency_cycles": [],
"violations": [],
"code_hash": "sha256:..."
}
INTERCAL Tripwire
INTERCAL does not execute production workloads. It acts as a compiler-shaped customs checkpoint: unpleasant, deterministic, and impossible for spaghetti code to charm its way through.
Julia and ASP decide whether code is safe.
INTERCAL encodes their decision into a compiler-enforced tripwire.
Violation Encoding
| Violation | INTERCAL Artifact |
|---|---|
| Alias violation | Invalid SELECT mask |
| Ownership cycle | Unresolved label dependency |
| Use-after-move | Missing resource array slot |
| Hidden mutation | Etiquette imbalance marker |
| Undeclared effect | Forbidden COME FROM edge |
| Type instability | Invalid width transition |
Valid Chain Template
10 REM BORROW CHAIN VERIFIED
20 MINGLE (SOURCE HASH)
30 SELECT (VALID MASK)
40 PRINT "CHAIN VERIFIED"
50 GOTO 50
Trust States
βββββββββββββββ
β UNTRUSTED β
ββββββββ¬βββββββ
β Gate 1 (parse)
βΌ
βββββββββββββββ
β PARSEABLE β
ββββββββ¬βββββββ
β Gate 2 (Isabelle proof)
βΌ
βββββββββββββββ
β PROVEN β
ββββββββ¬βββββββ
β Gate 3+4 (ASP policy)
βΌ
ββββββββββββββββββββ
β POLICY_COMPLIANT β
ββββββββ¬ββββββββββββ
β Gate 5-8 (Julia structural)
βΌ
βββββββββββββββββββββ
β STRUCTURALLY_VALIDβ
ββββββββ¬βββββββββββββ
β Gate 9 (INTERCAL tripwire)
βΌ
βββββββββββββββββββ
β CHAIN_VERIFIED β
ββββββββ¬βββββββββββ
β Gate 10 (receipt match)
βΌ
βββββββββββββββββββ
β RELEASABLE β
βββββββββββββββββββ
Failure Behavior
Any failed gate triggers:
- Freeze β source cannot be modified
- Quarantine β moved to
quarantine/directory - Receipt β violation receipt emitted
- Block β merge prevented
- No Binary β publication prevented
- Return β exact failed invariant returned to agent
Receipt Structure
{
"receipt_id": "rcpt_<16-hex>",
"source_hash": "sha256:<64-hex>",
"binary_hash": "sha256:<64-hex>",
"stages": {
"isabelle": {"status": "PROVED", "tokens": ["inv_..."]},
"asp": {"status": "SAT", "violations": []},
"julia_analysis": {"status": "STRUCTURALLY_VALID", ...},
"intercal": {"status": "PASS", "violation_class": "none"},
"julia_compile": {"status": "COMPILED", "binary_path": "..."}
},
"overall_status": "RELEASABLE",
"performance": {
"type_stable": true,
"allocations": 2,
"median_ns": 184,
"p99_ns": 211,
"threads": 1
},
"signature": "ed25519:...",
"timestamp": "2026-07-12T..."
}
Quick Start
# Clone
git clone https://github.com/SNAPKITTYWEST/cosmic-invariant-sieve.git
cd cosmic-invariant-sieve
# Full pipeline
make pipeline SOURCE=examples/valid/simple_function.jl
# Run tests
make test
# Verify a single source
make verify SOURCE=path/to/source.jl
# Run individual stages
make isabelle SOURCE=examples/valid/simple_function.jl
make asp SOURCE=examples/valid/simple_function.jl
make julia SOURCE=examples/valid/simple_function.jl
make intercal SOURCE=examples/valid/simple_function.jl
Repository Structure
cosmic-invariant-sieve/
βββ README.md β you are here
βββ LICENSE β Sovereign Source License v1.0
βββ Project.toml β Julia package definition
βββ Makefile β build orchestration
β
βββ docs/ β architecture documentation
β βββ ARCHITECTURE.md
β βββ BORROW_CHAIN.md
β βββ JULIA_EXECUTION_MODEL.md
β βββ FORMAL_TRUST_BOUNDARY.md
β βββ INTERCAL_TRIPWIRE.md
β βββ AGENT_CODE_POLICY.md
β
βββ schemas/ β JSON schemas for all data types
β βββ source-unit.schema.json
β βββ invariant-token.schema.json
β βββ borrow-event.schema.json
β βββ code-graph.schema.json
β βββ tripwire-result.schema.json
β βββ build-receipt.schema.json
β
βββ isabelle/ β formal proofs (Isabelle/HOL)
β βββ ROOT
β βββ Cosmic_Invariant_Sieve.thy
β βββ Quantum_State.thy
β βββ Matrix_Operators.thy
β βββ Program_Invariants.thy
β βββ Ownership_Model.thy
β βββ Borrow_Chain.thy
β βββ Effect_Safety.thy
β βββ Token_Extraction.thy
β
βββ asp/ β policy evaluation (Clingo)
β βββ cosmic_invariants.lp
β βββ ownership_rules.lp
β βββ borrow_rules.lp
β βββ effect_rules.lp
β βββ dependency_rules.lp
β βββ spaghetti_rules.lp
β βββ emit_status.lp
β βββ tests/
β
βββ julia/ β analysis + execution (Julia)
β βββ Project.toml
β βββ src/
β β βββ CosmicSieve.jl
β β βββ CanonicalIR.jl
β β βββ CodeGraph.jl
β β βββ Ownership.jl
β β βββ BorrowChain.jl
β β βββ EffectAnalysis.jl
β β βββ AllocationAnalysis.jl
β β βββ TypeStability.jl
β β βββ IntercalEmitter.jl
β β βββ NativeCompiler.jl
β β βββ Receipts.jl
β βββ test/
β βββ benchmarks/
β
βββ intercal/ β borrow-chain tripwire
β βββ profiles/
β βββ templates/
β βββ generated/
β βββ compiler_adapter.sh
β βββ tripwire_runner.sh
β
βββ pipeline/ β orchestration
β βββ cosmic-sieve
β βββ stages/
β β βββ 10-normalize-source.sh
β β βββ 20-run-isabelle.sh
β β βββ 30-export-invariants.sh
β β βββ 40-run-asp.sh
β β βββ 50-run-julia-analysis.sh
β β βββ 60-emit-intercal-chain.sh
β β βββ 70-run-tripwire.sh
β β βββ 80-compile-julia-native.sh
β β βββ 90-seal-receipt.sh
β βββ lib/
β βββ common.sh
β βββ hashing.sh
β βββ quarantine.sh
β βββ receipts.sh
β
βββ policies/ β TOML policy definitions
β βββ no-hidden-mutation.toml
β βββ no-unsafe-aliasing.toml
β βββ bounded-complexity.toml
β βββ deterministic-effects.toml
β βββ allocation-budget.toml
β βββ agent-output-policy.toml
β
βββ examples/ β test sources
β βββ valid/
β βββ rejected/
β
βββ receipts/ β build receipts (append-only)
βββ quarantine/ β quarantined sources
βββ tests/ β integration tests
βββ run-all.sh
βββ valid_pipeline.sh
βββ reject_alias_cycle.sh
βββ reject_spaghetti_graph.sh
βββ reject_unproved_invariant.sh
Agent Enforcement Model
Every agent-generated patch must pass all 10 gates:
Gate 1 β Parses into canonical IR
Gate 2 β Mathematical invariants compile in Isabelle
Gate 3 β All required invariant tokens are present
Gate 4 β ASP returns SATISFIABLE
Gate 5 β Julia reports type stability
Gate 6 β Julia reports valid ownership
Gate 7 β Julia reports valid borrow scopes
Gate 8 β Julia reports declared effects only
Gate 9 β INTERCAL tripwire compiles and exits correctly
Gate 10 β Julia native artifact matches source hash
Performance Principles
type-stable hot paths
precompiled sysimage
minimal dynamic dispatch
bounded allocations
immutable structures where practical
StaticArrays for small fixed matrices
LoopVectorization only where verified
multithreading only under deterministic partitioning
native compilation with PackageCompiler
benchmark receipts for every release
Citation
@software{cosmic-invariant-sieve2026,
author = {Ahmad Ali Parr},
title = {Cosmic Invariant Sieve: Formal Verification + Sovereign Borrow Chain},
year = {2026},
url = {https://github.com/SNAPKITTYWEST/cosmic-invariant-sieve}
}
License
Sovereign Source License v1.0 β See LICENSE
- Viewing, reading, auditing the source
- Running for personal or research use
- Forking for non-commercial, sovereign-aligned purposes
- Commercial use requires explicit written permission
- Modified versions cannot be redistributed under a different name
- Use in systems violating the sovereignty principle is prohibited
Β· β¦ Β· Β· β¦ Β· Β· β¦ Β· Β· β¦ Β·
NO PROOF β NO SAT β NO BINARY
THE SIEVE HOLDS.
Β· β¦ Β· Β· β¦ Β· Β· β¦ Β· Β· β¦ Β·
Cosmic Invariant Sieve Β· Sovereign Compute Architecture Β· 2026 Ahmad Ali Parr