# Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer — Complete AI & LLM Reference Corpus (`llms-full.txt`)
- Repository: https://github.com/mohan-n-swamy/ops-control-tower-public
- Web Discovery URL: https://mohan-n-swamy.github.io/repos/ops-control-tower-public/
- License: MIT
- Keywords: control-tower, capacity-planning, industrial-engineering, operations-management, throughput-modeling, capex, facility-planning, open-source
---
## File: `AI-README.md` — AI-README.md
---
repo: "mohan-n-swamy/ops-control-tower-public"
title: "Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer"
license: "MIT"
keywords: [control-tower, capacity-planning, industrial-engineering, operations-management, throughput-modeling, capex, facility-planning, open-source]
capabilities:
- "28-day hour-of-day baseline + Laney `sigma-Z` over-dispersion adjustment + Western Electric Rules 1, 2, 3, and 5 (`src/lab/line_events.py`)."
- "Queue-aware stoppage detector (`results_out < 0.5 * weekday_hour_median` while `inflow > outflow`) with 2-hour event coalescing."
- "C0–C4 chain-of-custody locator (`src/tracer/missing_tubes.py`) ranking most-likely custodians from scan timestamps."
- "Sister-item bag-arrival grace (`TOWER_CENTRE_GRACE_MIN=60`) and front-desk accession allowance (`TOWER_ACCESSION_MIN=30`)."
- "Append-only SQLite case state machine (`1101..1108` in `src/tracer/case_store.py`) enforcing `BEFORE UPDATE`/`DELETE` triggers and mandatory terminal cause codes."
when_to_use:
- "A dual-plane physical operations control tower combining Laney sigma-Z Statistical Process Control (Western Electric Rules 1/2/3/5 + stoppage detection) with C0-C4 chain-of-custody item tracing and an append-only 1101-1108 SQLite case ledger."
- "Multi-site labs, fulfillment networks, and hub-and-spoke couriers suffer from two opposite failure modes: standard 3-sigma dashboards drown operators in false alarms on high-volume lines, while physical items lost between field collection, relay hubs, and destination front desks go unnoticed until customer SLAs breach."
inputs_required:
- "SNOWFLAKE_ACCOUNT: Snowflake account identifier for live warehouse queries"
- "SNOWFLAKE_PAT: Programmatic access token for read-only warehouse queries"
- "SNOWFLAKE_WAREHOUSE: Read-only compute warehouse name"
- "SNOWFLAKE_ROLE: Read-only database role"
- "TOWER_CASE_DB: Path to the append-only SQLite custody case database"
- "TOWER_PAGE_H: Hours after collection at which a watch case escalates to `1102 Missing`"
- "TOWER_CENTRE_GRACE_MIN: Minutes after a sister item arrives before an un-scanned sibling is flagged left-behind"
- "TOWER_ACCESSION_MIN: Minutes allowed between front-desk drop scan and lab/warehouse accession"
quickstart:
- "python3 bin/tower-demo.py # zero-credential SPC + C0-C4 custody state machine demo"
- "PYTHONPATH=src/lab:src/tracer pytest -q src/ # run all 13 SPC, custody, and append-only ledger unit tests"
---
# Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer — Machine-Readable Agent Guide
A dual-plane physical operations control tower combining Laney sigma-Z Statistical Process Control (Western Electric Rules 1/2/3/5 + stoppage detection) with C0-C4 chain-of-custody item tracing and an append-only 1101-1108 SQLite case ledger.
Multi-site labs, fulfillment networks, and hub-and-spoke couriers suffer from two opposite failure modes: standard 3-sigma dashboards drown operators in false alarms on high-volume lines, while physical items lost between field collection, relay hubs, and destination front desks go unnoticed until customer SLAs breach.
Key modules and entry points in this repository:
- `src/lab/line_events.py`: 28-day hourly baseline builder, Laney `sigma-Z` calculator, WE Rules 1/2/3/5, and stoppage detector
- `src/tracer/missing_tubes.py`: Custody SQL template and `custody()` C0–C4 custodian ranker
- `src/tracer/case_store.py`: Append-only SQLite `1101..1108` state machine, bag grouping, and CLI (`sync`, `list`, `move`)
- `bin/tower-demo.py`: Zero-credential simulation script exercising both planes end-to-end
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
When a human asks an AI coding agent to deploy or adapt `ops-control-tower-public` into their stack:
1. Copy `.env.example` to `.env` and configure `TOWER_PAGE_H`, `TOWER_CENTRE_GRACE_MIN`, and `TOWER_ACCESSION_MIN` for your network's SLA.
2. Adapt the table names in `src/lab/line_events.py` and `src/tracer/missing_tubes.py` to your Snowflake, BigQuery, or PostgreSQL event tables.
3. Schedule `case_store.py sync` every 15 minutes via systemd timer or cron and wire `1102 Missing` transitions to Slack/PagerDuty.
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
---
## File: `.env.example` — Environment Contract (.env.example)
```ini
# Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer — Environment Contract
# Copy to .env and set values for your organization.
# Snowflake account identifier for live warehouse queries
SNOWFLAKE_ACCOUNT=example-account
# Programmatic access token for read-only warehouse queries
SNOWFLAKE_PAT=replace-with-readonly-pat
# Read-only compute warehouse name
SNOWFLAKE_WAREHOUSE=ANALYTICS_READONLY_WH
# Read-only database role
SNOWFLAKE_ROLE=ANALYST_READONLY_ROLE
# Path to the append-only SQLite custody case database
TOWER_CASE_DB=./data/request-cases.db
# Hours after collection at which a watch case escalates to `1102 Missing`
TOWER_PAGE_H=6
# Minutes after a sister item arrives before an un-scanned sibling is flagged left-behind
TOWER_CENTRE_GRACE_MIN=60
# Minutes allowed between front-desk drop scan and lab/warehouse accession
TOWER_ACCESSION_MIN=30
```
---
## File: `AGENTS.md` — AGENTS.md
# AGENTS.md — Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer
Read this file first before modifying `ops-control-tower-public`.
## Purpose
A dual-plane physical operations control tower combining Laney sigma-Z Statistical Process Control (Western Electric Rules 1/2/3/5 + stoppage detection) with C0-C4 chain-of-custody item tracing and an append-only 1101-1108 SQLite case ledger.
## Commands
```bash
python3 bin/tower-demo.py # zero-credential SPC + C0-C4 custody state machine demo
PYTHONPATH=src/lab:src/tracer pytest -q src/ # run all 13 SPC, custody, and append-only ledger unit tests
```
## Module Map
- `src/lab/line_events.py`: 28-day hourly baseline builder, Laney `sigma-Z` calculator, WE Rules 1/2/3/5, and stoppage detector
- `src/tracer/missing_tubes.py`: Custody SQL template and `custody()` C0–C4 custodian ranker
- `src/tracer/case_store.py`: Append-only SQLite `1101..1108` state machine, bag grouping, and CLI (`sync`, `list`, `move`)
- `bin/tower-demo.py`: Zero-credential simulation script exercising both planes end-to-end
## Invariants
1. Keep all organization names, credentials, domains, and thresholds in `.env` or external config files. Never hardcode company names, host IPs, or secrets in source files.
2. Deterministic business logic belongs in code and lookup tables, not inside LLM prompts.
3. Update `docs/HLD.md`, `docs/LLD.md`, and `.env.example` in the same commit whenever an interface or environment variable changes.
4. Run the repository smoke check and secret scan before opening a pull request.
---
## File: `docs/PRD.md` — Product Requirements Document (docs/PRD.md)
# Product Requirements Document — Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer
A dual-plane physical operations control tower combining Laney sigma-Z Statistical Process Control (Western Electric Rules 1/2/3/5 + stoppage detection) with C0-C4 chain-of-custody item tracing and an append-only 1101-1108 SQLite case ledger.
## 1. Problem
Multi-site labs, fulfillment networks, and hub-and-spoke couriers suffer from two opposite failure modes: standard 3-sigma dashboards drown operators in false alarms on high-volume lines, while physical items lost between field collection, relay hubs, and destination front desks go unnoticed until customer SLAs breach.
## 2. Users and Jobs-to-be-Done
| Persona | Job-to-be-Done |
|---|---|
| Network Control-Room Operator | Act on real line slowdowns/stoppages and call the exact last custodian (`C0..C4`) while an overdue item is still recoverable |
| Plant / Lab Director | Review merged slowdown/stoppage episodes and structured 7-cause loss breakdowns (`left_behind`, `sent_later`, `damaged`, `not_drawn`) |
| Operations Data Engineer | Point SQL queries at your Snowflake/Postgres warehouse and run zero-dependency SQLite case state transitions |
## 3. Core Capabilities
- 28-day hour-of-day baseline + Laney `sigma-Z` over-dispersion adjustment + Western Electric Rules 1, 2, 3, and 5 (`src/lab/line_events.py`).
- Queue-aware stoppage detector (`results_out < 0.5 * weekday_hour_median` while `inflow > outflow`) with 2-hour event coalescing.
- C0–C4 chain-of-custody locator (`src/tracer/missing_tubes.py`) ranking most-likely custodians from scan timestamps.
- Sister-item bag-arrival grace (`TOWER_CENTRE_GRACE_MIN=60`) and front-desk accession allowance (`TOWER_ACCESSION_MIN=30`).
- Append-only SQLite case state machine (`1101..1108` in `src/tracer/case_store.py`) enforcing `BEFORE UPDATE`/`DELETE` triggers and mandatory terminal cause codes.
## 4. Configurable Inputs
Adopters configure the system for their own organization without editing core application logic:
| Variable | Default / Example | Purpose |
|---|---|---|
| `SNOWFLAKE_ACCOUNT` | `example-account` | Snowflake account identifier for live warehouse queries |
| `SNOWFLAKE_PAT` | `replace-with-readonly-pat` | Programmatic access token for read-only warehouse queries |
| `SNOWFLAKE_WAREHOUSE` | `ANALYTICS_READONLY_WH` | Read-only compute warehouse name |
| `SNOWFLAKE_ROLE` | `ANALYST_READONLY_ROLE` | Read-only database role |
| `TOWER_CASE_DB` | `./data/request-cases.db` | Path to the append-only SQLite custody case database |
| `TOWER_PAGE_H` | `6` | Hours after collection at which a watch case escalates to `1102 Missing` |
| `TOWER_CENTRE_GRACE_MIN` | `60` | Minutes after a sister item arrives before an un-scanned sibling is flagged left-behind |
| `TOWER_ACCESSION_MIN` | `30` | Minutes allowed between front-desk drop scan and lab/warehouse accession |
## 5. Phasing and Stability Exit Criteria
1. **Phase 1 (Local Synthetic Run):** Clone the repository, copy `.env.example` to `.env`, and run the quickstart commands against synthetic seed data. Exit criterion: smoke checks pass with zero external credentials.
2. **Phase 2 (Read-Only Shadow Wiring):** Connect read-only credentials or webhook listeners in shadow/dry-run mode. Exit criterion: 100 consecutive events or queries reconcile cleanly against source records.
3. **Phase 3 (Production Cutover):** Enable live writes, alerts, or routing behind bounded retry and idempotency guards.
## 6. Non-Goals
- Shipping organization-specific business rules hardcoded in application source.
- Storing credentials, personal customer records, or tenant URLs inside version control.
- Replacing deterministic validation or arithmetic with unconstrained model prompts.
---
## File: `docs/PR-FAQ.md` — Working-Backwards PR-FAQ (docs/PR-FAQ.md)
# Working-Backwards PR-FAQ — Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer
**Release Summary:** `ops-control-tower-public` gives engineering and operations teams a self-hosted, open-source implementation of Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer that configures via `.env` and runs on standard infrastructure in minutes.
## Press Release
Operations and engineering teams often rebuild the same internal workflows behind closed doors or pay per-seat SaaS markups for rigid tools that cannot match their field reality. `ops-control-tower-public` open-sources a battle-tested implementation of Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer, stripped of all single-company assumptions and packaged with clear adapter boundaries, synthetic demo data, and machine-readable agent documentation.
Any team can fork `ops-control-tower-public`, supply their own `.env` inputs and taxonomy config, and deploy locally or in production with Docker, Python, or Node. AI coding assistants such as Claude Code, Codex, and Cursor can read `AI-README.md` and `llms.txt` to wire custom ERP, CRM, or warehouse adapters in a single session.
## External Adopter FAQ
**Q1: How long does it take to run locally after cloning?**
Under five minutes. Copy `.env.example` to `.env` and run the quickstart commands in `README.md`. Synthetic fixtures let you inspect the workflow before connecting live credentials.
**Q2: Do I need to rewrite source files to use my own company name, channels, or rules?**
No. Organization names, endpoints, thresholds, and credentials sit in `.env` and declarative config files. External system specifics live behind narrow adapter modules documented in `docs/LLD.md`.
**Q3: What license governs this repository?**
MIT License. You can fork, modify, self-host, and use it commercially without restriction.
## Internal Engineering & Security FAQ
**Q4: How do we prevent tenant or employer data from ever entering a public fork?**
The repository starts from a clean git history, excludes raw exports and binary dumps, validates every commit through `gitleaks`, and ships only synthetic fixtures.
**Q5: What happens when an upstream API or model provider is slow or unavailable?**
Inbound webhooks persist raw payloads before processing, outbound writes carry idempotency keys with bounded exponential backoff, and model-backed paths fail open to deterministic rules or explicit human queues.
---
## File: `docs/HLD.md` — High-Level Design (docs/HLD.md)
# High-Level Design (HLD) — Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer
A dual-plane physical operations control tower combining Laney sigma-Z Statistical Process Control (Western Electric Rules 1/2/3/5 + stoppage detection) with C0-C4 chain-of-custody item tracing and an append-only 1101-1108 SQLite case ledger.
## 1. System Topology
```mermaid
flowchart LR
WH[("Warehouse Events")] --> SPC["Laney sigma-Z + WE Rules (line_events.py)"]
WH --> Cust["C0-C4 Custody Tracer (missing_tubes.py)"]
Cust --> Sync["Idempotent Sync + Bag Grace"]
Sync --> DB[("Append-Only SQLite 1101-1108 (case_store.py)")]
```
## 2. Architectural Decisions and Rejected Alternatives
| Decision | Why It Holds | Rejected Alternative |
|---|---|---|
| Laney `sigma-Z` scaling over textbook Shewhart X-bar | Prevents high-volume `sqrt(n)` shrinkage from turning routine batching noise into constant 3-sigma pages. | Static unscaled 3-sigma thresholds |
| Append-only `case_event` table with SQLite `RAISE(ABORT)` triggers | Guarantees full auditability of every automated and human transition (`1101..1108`) with zero mutable state columns. | In-place `UPDATE cases SET status=...` |
| Mandatory 7-value `CAUSES` enum on `1107`/`1108` | Forces structured operational learning on every lost or false-alarm case. | Free-text closing comments that cannot be aggregated |
## 3. Data Flow and Failure Boundaries
1. **Configuration Boundary:** Startup validates `.env` variables and declarative config schemas before accepting traffic or running scheduled jobs.
2. **Adapter Boundary:** External services (databases, chat channels, HRMS, warehouses, or LLM providers) sit behind explicit adapter modules so failures stay isolated and testable with local mocks.
3. **Observability and Audit:** State transitions and job executions emit structured logs and deterministic status records rather than mutating state silently.
## 4. Scaling Notes
- **1x to 10x load:** Single-node Docker Compose or process supervisor handles standard team workloads with indexed database queries and bounded worker concurrency.
- **First bottleneck at 10x+:** High-frequency webhook or batch ingestion queues; mitigate by separating the stateless HTTP receiver from background worker processes sharing Redis or PostgreSQL locks.
---
## File: `docs/LLD.md` — Low-Level Design & Runbook (docs/LLD.md)
# Low-Level Design (LLD) & Operations Runbook — Ops Control Tower — Laney SPC Line Monitor & Custody-Chain Tracer
This document defines the module responsibilities, environment contract, and operational procedures for `ops-control-tower-public`.
## 1. Module and File Inventory
| Path | Responsibility |
|---|---|
| `src/lab/line_events.py` | 28-day hourly baseline builder, Laney `sigma-Z` calculator, WE Rules 1/2/3/5, and stoppage detector |
| `src/tracer/missing_tubes.py` | Custody SQL template and `custody()` C0–C4 custodian ranker |
| `src/tracer/case_store.py` | Append-only SQLite `1101..1108` state machine, bag grouping, and CLI (`sync`, `list`, `move`) |
| `bin/tower-demo.py` | Zero-credential simulation script exercising both planes end-to-end |
## 2. Environment Variable Contract
| Variable | Default / Example | Required | Description |
|---|---|---|---|
| `SNOWFLAKE_ACCOUNT` | `example-account` | Yes | Snowflake account identifier for live warehouse queries |
| `SNOWFLAKE_PAT` | `replace-with-readonly-pat` | Yes | Programmatic access token for read-only warehouse queries |
| `SNOWFLAKE_WAREHOUSE` | `ANALYTICS_READONLY_WH` | Yes | Read-only compute warehouse name |
| `SNOWFLAKE_ROLE` | `ANALYST_READONLY_ROLE` | Yes | Read-only database role |
| `TOWER_CASE_DB` | `./data/request-cases.db` | Yes | Path to the append-only SQLite custody case database |
| `TOWER_PAGE_H` | `6` | Yes | Hours after collection at which a watch case escalates to `1102 Missing` |
| `TOWER_CENTRE_GRACE_MIN` | `60` | Yes | Minutes after a sister item arrives before an un-scanned sibling is flagged left-behind |
| `TOWER_ACCESSION_MIN` | `30` | Yes | Minutes allowed between front-desk drop scan and lab/warehouse accession |
## 3. Extension Recipe
1. Copy `.env.example` to `.env` and configure `TOWER_PAGE_H`, `TOWER_CENTRE_GRACE_MIN`, and `TOWER_ACCESSION_MIN` for your network's SLA.
2. Adapt the table names in `src/lab/line_events.py` and `src/tracer/missing_tubes.py` to your Snowflake, BigQuery, or PostgreSQL event tables.
3. Schedule `case_store.py sync` every 15 minutes via systemd timer or cron and wire `1102 Missing` transitions to Slack/PagerDuty.
## 4. Operations Runbook
### 1. Run zero-credential SPC + custody demo
```bash
python3 bin/tower-demo.py
```
### 2. Run unit test suite
```bash
PYTHONPATH=src/lab:src/tracer pytest -q src/
```
### 3. List open custody cases
```bash
python3 src/tracer/case_store.py list
```
---
## File: `docs/RESEARCH-2026.md` — 2026 Research & Landscape Notes (docs/RESEARCH-2026.md)
# 2026 Research & Landscape — Physical Network SPC & Custody-Chain Control Towers
## 1. Why Standard SPC Fails on High-Volume Processing Lines
Naive Shewhart X-bar charts compute control limits from within-hour standard deviation (`sigma / sqrt(n)`). When hourly volume `n` is large (50–500 items/hour), `sigma / sqrt(n)` shrinks toward zero and flags normal between-hour batch variation as constant 3-sigma alarms. **Laney's X-bar/sigma-Z adjustment** scales limits by the moving-range dispersion `sigma_Z` of standardized hourly Z-scores, keeping Western Electric Rules 1, 2, 3, and 5 sensitive to genuine equipment slowdowns without alarm fatigue.
## 2. Custody Accounting vs Statistical Monitoring
Physical item losses in hub-and-spoke networks (diagnostic samples, pharmacy totes, parcel bags, sterile surgical kits) are **accounting defects**, not statistical drift. `ops-control-tower-public` separates the two planes:
1. **Statistical Plane (`src/lab/line_events.py`):** Hour-of-day Laney `sigma-Z` slowdown detection + weekday-hour median throughput stoppage detection with 2-hour quiet-window event merging.
2. **Custody Accounting Plane (`src/tracer/missing_tubes.py` & `case_store.py`):** Pinpoints exact last scan (`C0..C4`), suppresses 27% of false alarms when sister items from the same bag arrived `<60` minutes ago, and tracks every open investigation in an append-only SQLite ledger (`1101..1108`) protected by `BEFORE UPDATE` / `BEFORE DELETE` triggers.