Metadata-Version: 2.4
Name: tibet-cobol
Version: 0.1.1
Summary: COBOL legacy encapsulation with TIBET provenance and JIS capability gating
Project-URL: Homepage, https://github.com/Humotica/tibet-cobol
Project-URL: Repository, https://github.com/Humotica/tibet-cobol
Author-email: Humotica <info@humotica.com>
License: MIT
License-File: LICENSE
Keywords: audit,cobol,jis,legacy,migration,provenance,tibet
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.10
Requires-Dist: jis-core>=0.4.0b1
Requires-Dist: tibet-context>=0.2.0
Requires-Dist: tibet-core>=0.3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == 'dev'
Description-Content-Type: text/markdown

# tibet-cobol

COBOL legacy encapsulation with TIBET provenance and JIS capability gating.

> *The sarcophagus for COBOL: encapsulate without replacing.*

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

## The Problem

220 billion lines of COBOL power $3 trillion/day in transactions. Banks, governments, and insurers cannot rewrite it — too risky, too expensive, too critical. But without audit trails and capability gating, they cannot safely integrate AI either.

COBOL is the asbestos of programming languages. You can't remove it. You can encapsulate it.

## The Solution

tibet-cobol provides three layers for safe legacy modernization:

### 1. Bridge — Encapsulation

Wrap COBOL procedures with JIS capability gates and TIBET provenance chains. The business logic stays **identical** — zero changes to decades-tested rules.

```python
from tibet_cobol import COBOLBridge, PICType

bridge = COBOLBridge("FUNDS-TRANSFER")

# COBOL DATA DIVISION → Python (type-safe PIC fields)
bridge.define_storage(
    ("ACCOUNT-BAL", PICType.NUMERIC, 7, 2, 5000.00),
    ("TRANSFER-AMT", PICType.NUMERIC, 7, 2, 1500.00),
    ("TRANSFER-STAT", PICType.ALPHANUMERIC, 10, 0, ""),
)

# COBOL PROCEDURE DIVISION → Python (exact same logic)
def funds_transfer(ws):
    if ws.get("ACCOUNT-BAL") >= ws.get("TRANSFER-AMT"):
        ws.set("ACCOUNT-BAL", ws.get("ACCOUNT-BAL") - ws.get("TRANSFER-AMT"))
        ws.set("TRANSFER-STAT", "SUCCESS")
    else:
        ws.set("TRANSFER-STAT", "INSUFF-FND")

bridge.register_procedure("BEGIN-TRANSFER", funds_transfer)

# Execute with JIS gate + TIBET provenance
result = bridge.execute(
    procedure="BEGIN-TRANSFER",
    actor="ai-agent-001",
    model_id="qwen2.5:32b",   # 32B → gate OPEN (L2 access)
    required_level=2,
)
# result.status == "SUCCESS"
# result.tibet_tokens == [gate_check, pre_state, post_state]
```

A 3B model trying the same operation:
```python
result = bridge.execute(
    procedure="BEGIN-TRANSFER",
    actor="small-model",
    model_id="qwen2.5:3b",    # 3B → gate CLOSED (only L0)
    required_level=2,
)
# result.status == "DENIED"
# Violation logged in TIBET chain, state unchanged
```

### 2. Shadow — Parallel Execution

Run COBOL and the new system side by side. Compare outputs. Build trust over time.

```python
from tibet_cobol import ShadowRunner, ShadowMode

runner = ShadowRunner("FUNDS-TRANSFER")
runner.register_cobol(cobol_function)
runner.register_new(modern_function)

# Phase 1: Observe (COBOL master, new system watches)
result = runner.run({"balance": 5000, "amount": 1500}, mode=ShadowMode.SHADOW)

# Phase 2: Verify (both run, compare outputs)
result = runner.run({"balance": 5000, "amount": 1500}, mode=ShadowMode.VERIFY)
print(result.match)       # True — outputs identical
print(result.rag_entry)   # Knowledge captured for RAG

# Trust builds over many runs
for i in range(100):
    runner.run(test_data[i], mode=ShadowMode.VERIFY)
print(runner.trust.trust_score)     # 0.98
print(runner.trust.suggested_mode)  # ShadowMode.PARALLEL
```

### 3. Manifest — Field Mapping

Track which COBOL fields map to modern data stores. Bidirectional.

```python
from tibet_cobol import Manifest, MigrationStatus

manifest = Manifest("FUNDS-TRANSFER")

# Define mappings
manifest.map("ACCOUNT-BAL", "001-007", "9(7)V99",
             modern_path="accounts.balance", modern_type="decimal")
manifest.map("TRANSFER-AMT", "008-014", "9(7)V99",
             modern_path="transfers.amount", modern_type="decimal")
manifest.map("TRANSFER-STAT", "015-024", "X(10)")
# ^ No modern_path → stays COBOL_ONLY

# Update from shadow results
manifest.record_shadow("ACCOUNT-BAL", matched=True)  # ×100 runs

# Check migration readiness
print(manifest.coverage)           # 0.66 (2/3 fields mapped)
print(manifest.verification_score) # 0.95
print(manifest.ready_for_cutover)  # False (TRANSFER-STAT unmapped)

# Bidirectional lookup
manifest.cobol_to_modern("ACCOUNT-BAL")  # "accounts.balance"
manifest.modern_to_cobol("accounts.balance")  # "ACCOUNT-BAL"
```

## Migration Phases

```
Phase 0: SHADOW     COBOL master, new system observes
Phase 1: VERIFY     Both run, outputs compared
Phase 2: PARALLEL   New system serves, COBOL validates
Phase 3: CUTOVER    New system master, COBOL decommissioned
```

Every phase transition is:
- **JIS-gated** — requires proven capability
- **TIBET-tracked** — immutable provenance chain
- **Trust-based** — must reach threshold before advancing

## Installation

```bash
pip install tibet-cobol
```

Requires Python 3.10+ and [tibet-context](https://pypi.org/project/tibet-context/) >= 0.2.0.

## Tests

```bash
pytest tests/ -v
```

## Relation to TIBET Ecosystem

```
tibet-core        (Token, Chain, Provider)
    │
tibet-context     (Layers, Gate, Builder)
    │
tibet-cobol       (Bridge, Shadow, Manifest)  ← you are here
    │
Legacy COBOL      (FUNDS-TRANSFER, etc.)
```

## License

MIT — [Humotica](https://humotica.com)


## Credits

Designed by [Jasper van de Meent](https://github.com/jaspertvdm). Built by Jasper and [Root AI](https://humotica.com) as part of [HumoticaOS](https://humotica.com).

---

**Stack-positie:** Groep `specialized` · Eigen tijdlijn — niet onderdeel van de ainternet/evidence-spine · ← [`tibet-gateway`](https://pypi.org/project/tibet-gateway/) · [`tibet-y2k38`](https://pypi.org/project/tibet-y2k38/) → · See `STACK.md` · See `demo/golden-path/` for the spine end-to-end.
---

## Enterprise

For private hub hosting, SLA support, custom integrations, or compliance guidance:

| | |
|---|---|
| **Enterprise** | enterprise@humotica.com |
| **Support** | support@humotica.com |
| **Security** | security@humotica.com |

See [ENTERPRISE.md](ENTERPRISE.md) for details.
