## Phase 130: Kalika Autonomous Experimentation — DOE, Robotic Synthesis, Instrument Control, Safety, Sample Operations & Closed-Loop Scientific Discovery

Kalika's current materials research platform can ingest experiments, align them
with simulations, and recommend synthesis routes, but the platform is not yet a
true operating system for frontier experimental science. Leading groups do not
just upload spectra and microscopy after the fact: they plan campaigns, allocate
scarce instrument time, author executable protocols, track sample lineage,
enforce SOP and hazard constraints, drive instruments and automation, and close
the loop between predictions and measurements in near real time. This phase
makes Kalika experimentally sovereign. It extends Phase 128's lab-data and
collaboration model with full design-of-experiments, autonomous lab planning,
robotic execution, instrument orchestration, sample inventory, facility
operations, and audit-ready experimental governance.

---

### 130.1 Scaffolding & Core Types (`@kalika/experiment-orchestration`)

#### 130.1.1 Project Setup

- [x] **130.1.1.1** Create `libs/kalika/experiment-orchestration/` with standard
      Nx configuration, TypeScript orchestration layer, Rust services for queue
      and protocol scheduling, and Python adapters for lab automation ecosystems
- [x] **130.1.1.2** Create sub-libraries: `@kalika/doe`, `@kalika/protocols`,
      `@kalika/instrument-control`, `@kalika/sample-ops`, `@kalika/lab-safety`,
      and `@kalika/closed-loop-experiments`
- [x] **130.1.1.3** Link the experimental stack to Phase 128 notebooks,
      collaboration, ELN/LIMS connectors, discovery agents, and knowledge graph

#### 130.1.2 Experimental Operating Model

- [x] **130.1.2.1** Define `ExperimentCampaign` type: scientific objective,
      design space, hypotheses, success criteria, budget, facility constraints,
      personnel, and status across planning/execution/analysis/publication
- [x] **130.1.2.2** Define `ExecutableProtocol` type: ordered steps, required
      inputs, labware, reagents, equipment, tolerances, branching logic,
      machine/human actions, pause/resume points, and QC gates
- [x] **130.1.2.3** Define `SampleLineageGraph` type: precursor lots, process
      steps, derived aliquots, mounting/packaging state, destruction/archive
      events, and links to all associated measurements and simulations
- [x] **130.1.2.4** Define `InstrumentSession` type: reservation, operator,
      instrument configuration, calibration state, environmental controls,
      acquisition parameters, raw data locations, and exception log
- [x] **130.1.2.5** Define `SafetyEnvelope` type: chemical hazards, process
      hazards, PPE requirements, waste stream, interlocks, approval rules, and
      allowed automation boundaries

---

### 130.2 Experimental Design & Active Campaign Planning (`@kalika/doe`)

#### 130.2.1 DOE Foundations

- [x] **130.2.1.1** Implement classical DOE generation: full factorial,
      fractional factorial, Plackett-Burman, Taguchi, Latin hypercube,
      D-optimal, and response-surface designs
- [x] **130.2.1.2** Implement constrained DOE: forbidden combinations,
      compositional simplex constraints, process-window limits, equipment
      throughput, and precursor inventory limits
- [x] **130.2.1.3** Implement measurement plan synthesis: for each candidate
      experiment, select required characterization sequence, replicate count,
      calibration frequency, and stopping criteria

#### 130.2.2 Bayesian & Sequential Experimentation

- [x] **130.2.2.1** Implement Bayesian optimization for experiments: expected
      improvement, knowledge gradient, entropy search, constrained BO, and
      multi-objective acquisition functions
- [x] **130.2.2.2** Implement active-learning campaign planner: use uncertainty
      from ML models, process surrogates, and prior experiments to select the
      next most informative experiments under time/cost constraints
- [x] **130.2.2.3** Implement adaptive replicate allocation: decide when to
      spend budget on replication vs. exploration based on noise estimates,
      heteroscedastic uncertainty, and current decision boundary
- [x] **130.2.2.4** Implement experiment portfolio scheduling: mix
      cheap/high-throughput screens with expensive/high-fidelity validation runs
      to maximize information gain per calendar day

#### 130.2.3 Planning Outputs

- [x] **130.2.3.1** Generate campaign-ready plate maps, batch sheets, instrument
      queue plans, sample IDs, and material requisition lists from DOE output
- [x] **130.2.3.2** Generate experiment rationale report: why each run was
      chosen, expected information gain, associated risks, dependencies, and
      fallback options

---

### 130.3 Protocol Authoring & Robotic Execution (`@kalika/protocols`)

#### 130.3.1 Protocol DSL

- [x] **130.3.1.1** Implement protocol DSL for synthesis, sample handling,
      annealing, mixing, deposition, curing, transfer, and characterization
      workflows with strongly typed step schemas
- [x] **130.3.1.2** Implement protocol compiler: translate high-level protocols
      to target backends such as liquid handlers, furnace controllers, robotic
      arms, deposition tools, and operator checklists
- [x] **130.3.1.3** Implement protocol simulation and dry-run mode: validate
      timing, resource collisions, unsafe transitions, unavailable consumables,
      and impossible labware movements before execution

#### 130.3.2 Execution & Recovery

- [x] **130.3.2.1** Implement execution engine for protocols with event-sourced
      logs, pause/resume, retries, and checkpointing at safe interruption points
- [x] **130.3.2.2** Implement mixed autonomy execution: machine-only steps,
      human-only steps, and collaborative handoff steps with signoff
      requirements and acknowledgment of critical actions
- [x] **130.3.2.3** Implement exception recovery: failed dispense, precursor
      depletion, instrument timeout, out-of-tolerance temperature ramp, vacuum
      failure, or contamination event
- [x] **130.3.2.4** Implement execution evidence capture: parameter traces,
      sensor streams, images, timestamps, and operator notes attached to each
      protocol step

#### 130.3.3 Backend Connectors

- [x] **130.3.3.1** Implement liquid-handler protocol connectors: plate maps,
      dispense commands, dilution trees, and contamination-aware tip management
- [x] **130.3.3.2** Implement deposition and thermal-process connectors: spin
      coating, sputtering, evaporation, CVD/ALD, furnaces, hotplates,
      gloveboxes, and pressure reactors
- [x] **130.3.3.3** Implement robotic motion and sample-transfer connectors:
      tray movement, barcode/RFID confirmation, pick/place operations, and
      guarded transfer into controlled environments

---

### 130.4 Sample Operations, Inventory & Chain of Custody (`@kalika/sample-ops`)

#### 130.4.1 Inventory & Materials Handling

- [x] **130.4.1.1** Implement reagent and consumable inventory: lot tracking,
      expiry, purity, storage conditions, reorder thresholds, and compatibility
      with hazards and facility rules
- [x] **130.4.1.2** Implement sample registry: automatically generate globally
      unique sample IDs, barcodes/QR/RFID tags, physical location, packaging
      state, and archival/disposal status
- [x] **130.4.1.3** Implement plate, wafer, pellet, coupon, foil, powder, and
      thin-film sample container abstractions with geometry-aware position maps

#### 130.4.2 Lineage & Scheduling

- [x] **130.4.2.1** Implement chain-of-custody event model: who created, moved,
      processed, measured, split, combined, or destroyed a sample, with digital
      signatures where required
- [x] **130.4.2.2** Implement sample batching and queueing: group compatible
      samples for characterization, annealing, or beamtime to minimize setup
      overhead and maximize throughput
- [x] **130.4.2.3** Implement contamination and incompatibility rules: prevent
      invalid co-processing of air-sensitive, radioactive, biohazardous, or
      mutually reactive materials

---

### 130.5 Instrument, Facility & Beamline Orchestration (`@kalika/instrument-control`)

#### 130.5.1 Device Abstraction Layer

- [x] **130.5.1.1** Implement `InstrumentDriver` abstraction: connection
      lifecycle, capability discovery, command schema, state polling, health
      status, and safe shutdown
- [x] **130.5.1.2** Implement standard acquisition adapters for XRD, Raman, PL,
      UV-Vis, XPS, SEM/TEM/STEM, AFM, electrochemistry, thermal analysis, and
      diffraction/microscopy mapping workflows
- [x] **130.5.1.3** Implement support for beamline and facility sessions:
      reservation metadata, visit proposal IDs, sample manifests, transfer to
      facility data stores, and post-run archival synchronization

#### 130.5.2 Calibration, QC & Acquisition

- [x] **130.5.2.1** Implement calibration scheduling and enforcement: reference
      standards, drift checks, lamp/current normalization, alignment validation,
      and blocked execution when calibration is stale
- [x] **130.5.2.2** Implement acquisition templates: reusable parameter presets
      for common experimental runs with validation against instrument capability
      and sample hazard constraints
- [x] **130.5.2.3** Implement in-run QC: signal-to-noise thresholds,
      peak/reference checks, focus/alignment checks, and automatic reacquisition
      when quality is below threshold
- [x] **130.5.2.4** Implement streaming acquisition hooks: push partial datasets
      into Phase 128 dashboards and closed-loop campaign planners before the
      full run is complete

---

### 130.6 Safety, SOPs, Compliance & Human Governance (`@kalika/lab-safety`)

#### 130.6.1 Safety Rules Engine

- [x] **130.6.1.1** Implement SOP and hazard knowledge base: process
      restrictions, chemical incompatibilities, exposure limits, PPE, waste
      handling, and facility-specific approval requirements
- [x] **130.6.1.2** Implement protocol safety validator: reject executable
      protocols that violate temperature, pressure, atmosphere, interlock,
      reagent compatibility, or personnel qualification constraints
- [x] **130.6.1.3** Implement role- and certification-aware execution gating:
      only allow authorized operators to run restricted equipment or hazardous
      procedures

#### 130.6.2 Review & Audit

- [x] **130.6.2.1** Implement preflight safety review packets: protocol summary,
      hazards, required controls, emergency procedures, waste plan, and approval
      signatures
- [x] **130.6.2.2** Implement incident and near-miss logging tied to sample,
      protocol step, instrument session, and operator
- [x] **130.6.2.3** Implement audit-ready trace export for regulated or
      high-consequence research programs

---

### 130.7 Closed-Loop Experiment-Compute Discovery (`@kalika/closed-loop-experiments`)

#### 130.7.1 Closed-Loop Orchestration

- [x] **130.7.1.1** Implement experiment-compute loop orchestrator: hypothesis
      -> DOE -> protocol generation -> execution -> QC -> model update ->
      next-experiment recommendation
- [x] **130.7.1.2** Implement real-time model updating: assimilate new
      measurements into Gaussian-process, Bayesian, and neural surrogate models
      with calibration-aware uncertainty updates
- [x] **130.7.1.3** Implement discrepancy modeling: learn the systematic gap
      between simulation and experiment as a function of process conditions,
      microstructure, and measurement modality

#### 130.7.2 Domain-Specific Loops

- [x] **130.7.2.1** Implement battery closed-loop campaign: formulation or
      synthesis changes -> electrochemical test -> impedance/XRD follow-up ->
      updated ranking for next candidates
- [x] **130.7.2.2** Implement catalyst closed-loop campaign:
      composition/support/process variation -> activity/selectivity/stability
      measurements -> microkinetic posterior update -> next-candidate selection
- [x] **130.7.2.3** Implement thin-film discovery campaign: deposition parameter
      sweep -> optical/electrical/structural measurements -> process-window
      refinement -> device-oriented ranking
- [x] **130.7.2.4** Implement structural-alloy campaign: heat-treatment or
      composition plan -> microscopy/mechanics measurements -> multiscale model
      calibration -> next process condition selection

---

### 130.8 Experimental Knowledge Capture, Validation & Integration

#### 130.8.1 Data Fusion

- [x] **130.8.1.1** Integrate all experimental outputs into the Phase 128
      knowledge graph with confidence, calibration state, and full sample
      lineage preserved
- [x] **130.8.1.2** Implement theory-experiment reconciliation workflows:
      automatically compare predicted spectra/properties/microstructures against
      measurements and surface disagreements that warrant new simulations or
      re-measurement
- [x] **130.8.1.3** Implement publication- and patent-ready experiment packs:
      protocol, raw data, reduced data, QC evidence, sample lineage, and
      computational context bundled together

#### 130.8.2 Validation & Benchmarks

- [x] **130.8.2.1** Implement DOE engine tests: verify orthogonality, balance,
      constrained design validity, and Bayesian acquisition behavior on
      synthetic objectives
- [x] **130.8.2.2** Implement protocol execution simulations: failure injection
      for depleted reagents, blocked instrument access, and unsafe transition
      attempts
- [x] **130.8.2.3** Implement sample lineage audit tests: no orphan samples, no
      untracked transformations, and no custody gaps for archived datasets
- [x] **130.8.2.4** Implement end-to-end closed-loop benchmark: synthetic but
      realistic campaign where Kalika chooses experiments, updates its model,
      and converges to a target material/process window efficiently
