# SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower — Complete AI & LLM Reference Corpus (`llms-full.txt`) - Repository: https://github.com/mohan-n-swamy/supplyshift-public - Web Discovery URL: https://mohan-n-swamy.github.io/repos/supplyshift-public/ - License: MIT - Keywords: workforce-management, shift-scheduling, capacity-planning, operations-research, field-operations, demand-forecasting, typescript, docker, open-source --- ## File: `AI-README.md` — AI-README.md --- repo: "mohan-n-swamy/supplyshift-public" title: "SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower" license: "MIT" keywords: [workforce-management, shift-scheduling, capacity-planning, operations-research, field-operations, demand-forecasting, typescript, docker, open-source] capabilities: - "Per-hub utilization and 15-minute slot overbooking detector (`src/overbookings.ts`) with exact City -> Hub -> Slot reconciliation." - "Ordered P0..P5 donor-hub staff movement recommender (`src/movement-engine.ts`) with donor safety floors and standby activation fallbacks." - "Largest-cover same-address / household batching calculator (`sameHomeSavings` in `src/sheets-client.ts`)." - "Append-only SQLite snapshot scheduler (`plan_snapshots`, `availability_polls`, `demand_snapshots`) with 1-hour stale-lock recovery (`src/jobs/job-runs.ts`)." - "Per-30-minute bucket Combined Demand Loss (`CDL(t) = max(0, Ba(t) - Xa(t))`) derivation engine (`src/history/derive.ts`)." when_to_use: - "A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL)." - "Field operations teams lose orders every morning when customer bookings cluster into peak 15-minute slots at one hub while neighboring hubs sit at 35% utilization, or when mid-shift attendance drops go unnoticed until SLAs fail." inputs_required: - "PORT: HTTP port for the Express server and static control-room UI" - "SCHEDULER_API_URL: Base URL of your workforce/task scheduler REST API" - "ALLOWED_AUTH_DOMAIN: Google Workspace email domain permitted to sign in" - "GOOGLE_CLIENT_ID: Google OAuth 2.0 Web Client ID" - "GOOGLE_CLIENT_SECRET: Google OAuth 2.0 Web Client Secret" - "GOOGLE_REDIRECT_URI: OAuth 2.0 callback URL" - "GOOGLE_SHEETS_SPREADSHEET_ID: Optional Google Sheet ID holding Hub List intervals and P0..P5 donor rules" - "SAME_HOME_SHEET_ID: Optional Google Sheet ID for multi-order same-address batching" quickstart: - "npm install" - "npm run demo # zero-credential synthetic hub movement & overbooking simulation" - "npm test # runs all 4 TypeScript test suites (auth/locks, slots, CDL history, overbookings)" - "npm run lint # strict TypeScript typecheck (tsc --noEmit)" --- # SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower — Machine-Readable Agent Guide A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL). Field operations teams lose orders every morning when customer bookings cluster into peak 15-minute slots at one hub while neighboring hubs sit at 35% utilization, or when mid-shift attendance drops go unnoticed until SLAs fail. Key modules and entry points in this repository: - `src/overbookings.ts`: 15-minute slot excess calculator (`booked > fMedics`) and City/Hub/Slot rollup aggregator - `src/movement-engine.ts`: Ordered donor-hub staff transfer solver and standby activation recommender - `src/dashboard.ts`: Live shift-window slot, booking, utilization, and pass-through cadence builder - `src/history/derive.ts`: Per-bucket Plan-vs-Actual Combined Demand Loss (CDL) and absent-specialist attribution - `src/sheets-client.ts`: Google Sheets JWT reader + largest-cover same-address grouping calculator - `src/demo.ts`: Zero-credential synthetic simulation CLI 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 `supplyshift-public` into their stack: 1. Copy `.env.example` to `.env` and set `ALLOWED_AUTH_DOMAIN`, `SCHEDULER_API_URL`, and `PORT`. 2. Adapt `fetchHubs`, `fetchSpecialists`, and `fetchDemand` in `src/scheduler-client.ts` to match your dispatch API JSON shape. 3. Configure your hub slot intervals (e.g., 30m vs 45m) in `src/config.ts` or via `GOOGLE_SHEETS_SPREADSHEET_ID`. - 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 # SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower — Environment Contract # Copy to .env and set values for your organization. # HTTP port for the Express server and static control-room UI PORT=3800 # Base URL of your workforce/task scheduler REST API SCHEDULER_API_URL=https://scheduler-api.ops.example.org # Google Workspace email domain permitted to sign in ALLOWED_AUTH_DOMAIN=ops.example.org # Google OAuth 2.0 Web Client ID GOOGLE_CLIENT_ID=000000000000-exampleoauthclientid.apps.googleusercontent.com # Google OAuth 2.0 Web Client Secret GOOGLE_CLIENT_SECRET=replace-with-oauth-client-secret # OAuth 2.0 callback URL GOOGLE_REDIRECT_URI=http://localhost:3800/api/auth/callback # Optional Google Sheet ID holding Hub List intervals and P0..P5 donor rules GOOGLE_SHEETS_SPREADSHEET_ID=10000000000000000000000000000000000000000000 # Optional Google Sheet ID for multi-order same-address batching SAME_HOME_SHEET_ID=10000000000000000000000000000000000000000001 ``` --- ## File: `AGENTS.md` — AGENTS.md # AGENTS.md — SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower Read this file first before modifying `supplyshift-public`. ## Purpose A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL). ## Commands ```bash npm install npm run demo # zero-credential synthetic hub movement & overbooking simulation npm test # runs all 4 TypeScript test suites (auth/locks, slots, CDL history, overbookings) npm run lint # strict TypeScript typecheck (tsc --noEmit) ``` ## Module Map - `src/overbookings.ts`: 15-minute slot excess calculator (`booked > fMedics`) and City/Hub/Slot rollup aggregator - `src/movement-engine.ts`: Ordered donor-hub staff transfer solver and standby activation recommender - `src/dashboard.ts`: Live shift-window slot, booking, utilization, and pass-through cadence builder - `src/history/derive.ts`: Per-bucket Plan-vs-Actual Combined Demand Loss (CDL) and absent-specialist attribution - `src/sheets-client.ts`: Google Sheets JWT reader + largest-cover same-address grouping calculator - `src/demo.ts`: Zero-credential synthetic simulation CLI ## 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 — SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL). ## 1. Problem Field operations teams lose orders every morning when customer bookings cluster into peak 15-minute slots at one hub while neighboring hubs sit at 35% utilization, or when mid-shift attendance drops go unnoticed until SLAs fail. ## 2. Users and Jobs-to-be-Done | Persona | Job-to-be-Done | |---|---| | Central Dispatch / Supply Lead | Spot hubs with `booked > active_staff` in Today (D0) and Tomorrow (D+1) windows and execute donor-hub transfers before the shift starts | | City / Hub Operations Manager | Separate D-1 roster planning gaps from day-of specialist absenteeism using per-bucket SQLite CDL history | | Workforce Planning Engineer | Configure city slot intervals (30m vs 45m), donor adjacency priority lists, and scheduler API adapters via `.env` | ## 3. Core Capabilities - Per-hub utilization and 15-minute slot overbooking detector (`src/overbookings.ts`) with exact City -> Hub -> Slot reconciliation. - Ordered P0..P5 donor-hub staff movement recommender (`src/movement-engine.ts`) with donor safety floors and standby activation fallbacks. - Largest-cover same-address / household batching calculator (`sameHomeSavings` in `src/sheets-client.ts`). - Append-only SQLite snapshot scheduler (`plan_snapshots`, `availability_polls`, `demand_snapshots`) with 1-hour stale-lock recovery (`src/jobs/job-runs.ts`). - Per-30-minute bucket Combined Demand Loss (`CDL(t) = max(0, Ba(t) - Xa(t))`) derivation engine (`src/history/derive.ts`). ## 4. Configurable Inputs Adopters configure the system for their own organization without editing core application logic: | Variable | Default / Example | Purpose | |---|---|---| | `PORT` | `3800` | HTTP port for the Express server and static control-room UI | | `SCHEDULER_API_URL` | `https://scheduler-api.ops.example.org` | Base URL of your workforce/task scheduler REST API | | `ALLOWED_AUTH_DOMAIN` | `ops.example.org` | Google Workspace email domain permitted to sign in | | `GOOGLE_CLIENT_ID` | `000000000000-exampleoauthclientid.apps.googleusercontent.com` | Google OAuth 2.0 Web Client ID | | `GOOGLE_CLIENT_SECRET` | `replace-with-oauth-client-secret` | Google OAuth 2.0 Web Client Secret | | `GOOGLE_REDIRECT_URI` | `http://localhost:3800/api/auth/callback` | OAuth 2.0 callback URL | | `GOOGLE_SHEETS_SPREADSHEET_ID` | `10000000000000000000000000000000000000000000` | Optional Google Sheet ID holding Hub List intervals and P0..P5 donor rules | | `SAME_HOME_SHEET_ID` | `10000000000000000000000000000000000000000001` | Optional Google Sheet ID for multi-order same-address batching | ## 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 — SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower **Release Summary:** `supplyshift-public` gives engineering and operations teams a self-hosted, open-source implementation of SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower 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. `supplyshift-public` open-sources a battle-tested implementation of SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower, stripped of all single-company assumptions and packaged with clear adapter boundaries, synthetic demo data, and machine-readable agent documentation. Any team can fork `supplyshift-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) — SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower A TypeScript and SQLite operations control tower for multi-hub field workforces that detects 15-minute slot overbookings, recommends donor-hub staff transfers, credits same-address order batching, and attributes plan-vs-actual Combined Demand Loss (CDL). ## 1. System Topology ```mermaid flowchart LR Sched["Scheduler API (Hubs, Shifts, Demand)"] --> Dash["Hub Utilization & Overbookings Engine"] Sheets["Hub Intervals & Donor Rules"] --> Move["P0..P5 Movement Solver"] Dash --> Move Polls["D-1 Plan + 30m Presence Polls"] --> SQLite[("SQLite WAL History")] SQLite --> CDL["Per-Bucket CDL Attribution"] ``` ## 2. Architectural Decisions and Rejected Alternatives | Decision | Why It Holds | Rejected Alternative | |---|---|---| | Separate window slot-outs from 15-minute slot overbookings | A hub with 20 daily slots and 12 bookings still fails if 8 bookings land at 07:00 with only 4 specialists. | Relying solely on shift-wide utilization averages | | Never cache partial city API failures | Surfaces partial upstream failures in `warnings[]` without poisoning the 30-minute in-memory cache. | Caching empty arrays on transient 502s | | Local SQLite WAL for D-1 and 30-minute polls | Zero external database setup while capturing mid-shift specialist drop-offs at 30-minute granularity. | Stateless dashboard with no historical memory | ## 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 — SupplyShift — Workforce Capacity, Slot Overbooking & Shift Movement Tower This document defines the module responsibilities, environment contract, and operational procedures for `supplyshift-public`. ## 1. Module and File Inventory | Path | Responsibility | |---|---| | `src/overbookings.ts` | 15-minute slot excess calculator (`booked > fMedics`) and City/Hub/Slot rollup aggregator | | `src/movement-engine.ts` | Ordered donor-hub staff transfer solver and standby activation recommender | | `src/dashboard.ts` | Live shift-window slot, booking, utilization, and pass-through cadence builder | | `src/history/derive.ts` | Per-bucket Plan-vs-Actual Combined Demand Loss (CDL) and absent-specialist attribution | | `src/sheets-client.ts` | Google Sheets JWT reader + largest-cover same-address grouping calculator | | `src/demo.ts` | Zero-credential synthetic simulation CLI | ## 2. Environment Variable Contract | Variable | Default / Example | Required | Description | |---|---|---|---| | `PORT` | `3800` | Yes | HTTP port for the Express server and static control-room UI | | `SCHEDULER_API_URL` | `https://scheduler-api.ops.example.org` | Yes | Base URL of your workforce/task scheduler REST API | | `ALLOWED_AUTH_DOMAIN` | `ops.example.org` | Yes | Google Workspace email domain permitted to sign in | | `GOOGLE_CLIENT_ID` | `000000000000-exampleoauthclientid.apps.googleusercontent.com` | Yes | Google OAuth 2.0 Web Client ID | | `GOOGLE_CLIENT_SECRET` | `replace-with-oauth-client-secret` | Yes | Google OAuth 2.0 Web Client Secret | | `GOOGLE_REDIRECT_URI` | `http://localhost:3800/api/auth/callback` | Yes | OAuth 2.0 callback URL | | `GOOGLE_SHEETS_SPREADSHEET_ID` | `10000000000000000000000000000000000000000000` | Yes | Optional Google Sheet ID holding Hub List intervals and P0..P5 donor rules | | `SAME_HOME_SHEET_ID` | `10000000000000000000000000000000000000000001` | Yes | Optional Google Sheet ID for multi-order same-address batching | ## 3. Extension Recipe 1. Copy `.env.example` to `.env` and set `ALLOWED_AUTH_DOMAIN`, `SCHEDULER_API_URL`, and `PORT`. 2. Adapt `fetchHubs`, `fetchSpecialists`, and `fetchDemand` in `src/scheduler-client.ts` to match your dispatch API JSON shape. 3. Configure your hub slot intervals (e.g., 30m vs 45m) in `src/config.ts` or via `GOOGLE_SHEETS_SPREADSHEET_ID`. ## 4. Operations Runbook ### 1. Run zero-credential simulation ```bash npm run demo ``` ### 2. Execute all 4 automated test suites ```bash npm test ``` ### 3. Type-check full codebase ```bash npm run lint ``` ### 4. Start local control-room server ```bash cp .env.example .env && npm run dev ``` --- ## File: `docs/RESEARCH-2026.md` — 2026 Research & Landscape Notes (docs/RESEARCH-2026.md) # 2026 Research & Landscape — Workforce Shift Rostering & Slot Capacity Optimization ## 1. Domain Landscape (2026) Open-source shift planners such as **Schichtplaner**, **TimeTrex CE**, and **BetterShift** handle weekly calendar CRUD, while constraint solvers such as **Timefold** and **Google OR-Tools (CP-SAT)** solve static offline rosters. In live field operations (home diagnostics, appliance repair, grocery delivery, mobile nursing), static rosters break between 06:00 and 10:00 when demand spikes in specific 15-minute slots or a rostered specialist drops off mid-shift. ## 2. Architectural Differentiators in SupplyShift 1. **Window Slot-Outs vs Per-Slot Overbookings:** Window capacity (`bookings - staff * slots_per_staff`) hides 15-minute pile-ups when all bookings cluster at `07:00`. `src/overbookings.ts` computes exact per-slot excess (`max(0, booked_in_slot - active_staff)`) alongside window utilization. 2. **Priority Donor-Hub Movement Engine (`src/movement-engine.ts`):** Evaluates ordered donor-hub adjacency lists (`P0..P5`), ensuring a donor hub never drops into risk while ranking direct transfers ahead of off-shift activations. 3. **Household / Same-Address Batching Credit (`src/sheets-client.ts`):** Deducts multi-order same-address groupings (`n - 1` slot savings) so dispatchers do not over-allocate staff to grouped visits. 4. **Plan-vs-Actual Combined Demand Loss (`src/history/derive.ts`):** Polls live presence every 30 minutes into SQLite (`better-sqlite3` WAL) and separates D-1 roster under-planning from day-of attendance loss.