# Kalika Build Order

This document is the phase-level build graph for Kalika phases 99-115. It is
intended for implementation planning, CI sequencing, and avoiding late-phase
dependencies on packages that are not buildable yet.

## Critical Path

The longest dependency chain for the pre-materials Kalika core is:

```text
99 foundation
  -> 103 numerical engine
  -> @kalika/autodiff-core and @kalika/sdp-core
  -> 104 formal/AI/PINN work and 109 bootstrap work
  -> 113 optimization/autodiff facades
  -> 114 capstone libraries
  -> 115 architecture hardening and final coverage
```

Two early core packages are deliberately placed after the numerical engine and
before their historical parent phases:

- `@kalika/autodiff-core`: forward/reverse automatic differentiation extracted
  from phase 113 so phase 104 PINNs and differentiable physics can build early.
- `@kalika/sdp-core`: dependency-free semidefinite programming extracted from
  phase 113 so phase 109 conformal bootstrap code can build before the full
  optimization package exists.

The late facades still exist:

- `@kalika/autodiff` remains the phase 113 package for CAS adjoints and
  higher-level AD integrations.
- `@kalika/optimization` remains the phase 113 package for LP, SDP exports,
  convex, nonlinear, global, verified, and variational optimization.

## Phase DAG

```mermaid
flowchart TD
  P99["99 foundation: core, CAS, arithmetic"]
  P100["100 pure math"]
  P101["101 theoretical physics I"]
  P102["102 advanced physics"]
  P103["103 computational engine"]
  ADCORE["@kalika/autodiff-core"]
  SDPCORE["@kalika/sdp-core"]
  P104["104 formal verification and AI research"]
  P105["105 research platform"]
  P106["106 integration, SDK, apps"]
  P107["107 workbench UI"]
  P108["108 ML sovereignty"]
  P109["109 frontier methods"]
  P110["110 advanced mathematics"]
  P111["111 interoperability and verification"]
  P112["112 classical and continuum physics"]
  P113["113 final completeness"]
  P114["114 capstone"]
  P115["115 architecture hardening"]

  P99 --> P100
  P99 --> P101
  P99 --> P103
  P99 --> P105

  P100 --> P101
  P100 --> P102
  P100 --> P110
  P100 --> P112

  P101 --> P102
  P101 --> P112

  P103 --> ADCORE
  P103 --> SDPCORE
  P103 --> P104
  P103 --> P108
  P103 --> P109
  P103 --> P112

  ADCORE --> P104
  ADCORE --> P109
  ADCORE --> P113
  SDPCORE --> P109
  SDPCORE --> P113

  P104 --> P108
  P104 --> P111
  P105 --> P106
  P105 --> P107
  P105 --> P108
  P106 --> P107
  P106 --> P111

  P102 --> P109
  P102 --> P114
  P109 --> P113
  P110 --> P113
  P111 --> P113
  P112 --> P113
  P108 --> P113
  P113 --> P114
  P114 --> P115
```

## Dependency Table

| Phase or package          | Direct prerequisites              | Blocks                                     | Notes                                                                  |
| ------------------------- | --------------------------------- | ------------------------------------------ | ---------------------------------------------------------------------- |
| 99 foundation             | none                              | every Kalika package                       | Core expression, CAS, arithmetic, and initial scaffolding baseline.    |
| 100 pure math             | 99                                | 101, 102, 109, 110, 112                    | Algebra, analysis, topology, category theory, probability.             |
| 101 theoretical physics I | 99, 100                           | 102, 112, QFT/GR glue in 115               | First physics layer; QFT and GR are reused throughout later phases.    |
| 102 advanced physics      | 99-101                            | 109, 114, later phenomenology glue         | String, condensed matter, cosmology, HEP, QG, GW, lattice.             |
| 103 computational engine  | 99                                | AD core, SDP core, 104, 108, 109, 112, 113 | Numerical, tensor-network, Monte Carlo, FEM/spectral, HPC foundation.  |
| `@kalika/autodiff-core`   | 99, 103                           | 104.6, 109.7, 113.2                        | Dependency-free forward/reverse AD.                                    |
| `@kalika/sdp-core`        | 99, 103                           | 109.5, 113.1                               | Dependency-free SDP solver and SDP types.                              |
| 104 formal/AI research    | 99, 100, 103, AD core             | 108, 111, 113                              | Lean/ATP, research agents, symbolic regression, PINNs.                 |
| 105 research platform     | 99 plus available domain packages | 106, 107, 108, 111                         | Notebooks, renderer, typesetting, citations, knowledge graph.          |
| 106 integration           | 99-105 usable package surfaces    | 107, 111, 113                              | Database, SDK, apps, cross-domain workflows, benchmarks.               |
| 107 UI/UX                 | 105, 106                          | final user-facing validation in 115        | Workbench and notebook user experience.                                |
| 108 ML sovereignty        | 103, 104, 105                     | 113, data flywheel tests in 115            | Training data, KG infra, custom models, serving.                       |
| 109 frontier methods      | 100, 102, 103, AD core, SDP core  | 113, 114                                   | Bootstrap must use `@kalika/sdp-core`; differentiable physics uses AD. |
| 110 advanced mathematics  | 100                               | 113, 114                                   | Algebraic geometry, geometric analysis, higher categories, VOAs.       |
| 111 interoperability      | 104, 105, 106                     | 113, reproducibility work in 115           | Data formats, CAS bridges, proof import/export, verification.          |
| 112 continuum physics     | 100, 101, 103                     | 113, 114                                   | Classical mechanics through atomic physics.                            |
| 113 final completeness    | 108-112 plus AD core and SDP core | 114, 115                                   | Full optimization, full AD, measure/approximation/combinatorics.       |
| 114 capstone              | 102, 110, 112, 113                | 115                                        | Non-perturbative QFT, spectral geometry, optimal transport, chaos.     |
| 115 hardening             | 99-114                            | materials phases 116-128                   | Glue, scaffold completion, build fixes, and final coverage.            |

## Parallel Work Lanes

After phase 99 is stable, implementation can proceed in parallel along these
lanes. Run package-level verification per lane and use affected Nx targets when
cross-lane changes land.

| Lane               | Sequence                  | Can run in parallel with                  | Synchronization points                                                  |
| ------------------ | ------------------------- | ----------------------------------------- | ----------------------------------------------------------------------- |
| Pure math          | 100 -> 110                | Physics, platform, compute                | Join at 109/113 when frontier/final packages need math APIs.            |
| Physics            | 101 -> 102 -> 112         | Pure math after shared APIs settle        | Join at 109/114 and phase 115 glue tasks.                               |
| Compute foundation | 103 -> AD core + SDP core | Pure math and platform                    | Must finish before 104.6, 109.5, 109.7, 113.1, 113.2.                   |
| Formal and AI      | 104 -> 108                | Platform, advanced math                   | Depends on AD core for PINNs; joins at 113.                             |
| Platform           | 105 -> 106 -> 107         | Math/physics once package contracts exist | Joins at 111 and final user-facing validation.                          |
| Frontier methods   | 109                       | 110 and 112 after prerequisites           | Bootstrap waits for SDP core; differentiable physics waits for AD core. |
| Interop            | 111                       | 110 and 112                               | Requires 104 proof formats and 105/106 platform data.                   |
| Finalization       | 113 -> 114 -> 115         | none as a broad lane                      | Treat as the final fan-in; keep checks targeted but comprehensive.      |

## Build Rules

- Do not make phases 104-112 import from phase 113 facades when a required
  primitive has an early core package. Use `@kalika/autodiff-core` and
  `@kalika/sdp-core` directly in earlier phases.
- Keep early core packages dependency-free at runtime. They may have Vitest as a
  dev dependency, but they must not require later Kalika packages to build.
- Late packages may re-export early packages for compatibility, but they should
  not own the only implementation of a primitive needed by earlier phases.
- When adding a package-level dependency, update `package.json`,
  `tsconfig.base.json` path aliases, and the lockfile together.
- For broad validation, prefer affected or targeted Nx commands until the final
  fan-in. On small/no-swap hosts, keep broad gates serialized.
