# Swift Reference Implementation

The repository now includes a native Swift package at `swift/CapsulangSwift`.

Its role is to provide a dependency-free Apple-platform runtime/reference SDK while keeping the existing Python implementation as the canonical authoring/tooling implementation and Lean 4 as the proof target.

## Components

- `CapsulangCore`: parser, AST, checker, interpreter, canonical IR/hash, machine runtime, effect intents, ledger, and trace helpers.
- `caps-swift`: macOS/CI command-line interface for parse/check/examples/hash/call.
- `CapsulangCoreTests`: conformance-style tests over the existing examples plus runtime semantics tests.

## Runtime boundary

The Swift machine runtime does **not** execute database, UI, agent, or network effects directly. It returns `EffectIntent` values. Host apps on iOS, macOS, watchOS, tvOS, and visionOS retain authority over which effects may execute.

## Validation

Run from `swift/CapsulangSwift`:

```bash
swift test
```

The intentionally invalid `examples/04_bad_missing_effect.caps` is expected to produce `E_EFFECT_NOT_DECLARED`.

## Improvement governance support

The Swift package now includes the same CPS-8 improvement-governance surface as the Python reference implementation:

- `lineage`
- `objective`
- `eval-suite`
- `successor-contract`
- `budget`
- `gate`
- `deployment-policy`
- `improvement-record`
- `verification-hook`

These declarations are parsed into native Swift AST types, checked for unresolved references and unsafe deployment gating, and included in the canonical IR/semantic hash. Improvement effects such as `eval.run`, `proof.verify`, `approval.request`, and `deploy.canary` remain capability-safe `EffectIntent` data for the host app to approve and execute.
