{
  "openapi": "3.1.0",
  "info": {
    "title": "Clock-Anything API (ANY-A12)",
    "version": "1.0.0",
    "summary": "Deterministic Critical-Path Launch Clock, Statutory Deadline Roll-Forward & Public Portal Probe Engine",
    "description": "Polymorphic deterministic Critical Path Method (CPM) scheduler, forward/backward launch-clock planner, US/UK/SG/HK/EU statutory holiday & leap-year roll-forward engine, expedite cost/days-saved ROI comparator, and safe read-only official portal probe backed by 7d-30d cross-tenant archive cache. Enforces strict $0 billing (charged_micros == 0, billed_micros == 0) on HTTP 422, DAG cycles, invalid dates/jurisdictions, or upstream errors. Informational timeline planning and public portal checks only; NOT licensed legal, regulatory, customs, tax, or CPA advice.",
    "contact": {
      "name": "Clock-Anything Operations",
      "url": "https://clock.fastmesh.dev",
      "email": "ops@fastmesh.dev"
    }
  },
  "servers": [
    {
      "url": "https://clock.fastmesh.dev",
      "description": "Production HTTPS gateway"
    },
    {
      "url": "http://127.0.0.1:8812",
      "description": "Local development upstream"
    }
  ],
  "tags": [
    { "name": "Health", "description": "Service liveness, SQLite WAL status, and archive cache metrics" },
    { "name": "Catalog", "description": "Built-in 5-category critical-path templates and statutory holiday calendars" },
    { "name": "Planning", "description": "CPM forward/backward scheduling, expedite ROI comparison, and batch multi-jurisdiction evaluation" },
    { "name": "Portals", "description": "Read-only official public portal probes with 7d-30d cross-tenant archive cache" },
    { "name": "Billing", "description": "Prepaid Creem SKU packs, micro-USD balances, and HMAC-SHA256 webhooks" },
    { "name": "MCP", "description": "Native JSON-RPC 2.0 Model Context Protocol endpoint" }
  ],
  "paths": {
    "/": {
      "get": {
        "tags": ["Health"],
        "operationId": "getTryNowConsole",
        "summary": "Serve the 5-second Try-Now interactive Gantt launch-clock console",
        "responses": {
          "200": {
            "description": "HTML Try-Now Console",
            "content": { "text/html": { "schema": { "type": "string" } } }
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": ["Health"],
        "operationId": "getHealth",
        "summary": "Check service liveness, SQLite WAL billing status, and archive cache health",
        "responses": {
          "200": {
            "description": "Service health snapshot",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/HealthResponse" } }
            }
          }
        }
      }
    },
    "/api/catalog": {
      "get": {
        "tags": ["Catalog"],
        "operationId": "getCatalog",
        "summary": "List all 5 clock categories and 21 built-in critical-path scenario templates (alias: /api/scenarios)",
        "responses": {
          "200": {
            "description": "Catalog of categories and scenarios",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/CatalogResponse" } }
            }
          }
        }
      }
    },
    "/api/scenarios": {
      "get": {
        "tags": ["Catalog"],
        "operationId": "getScenariosAlias",
        "summary": "Alias for /api/catalog returning built-in scenarios by category",
        "responses": {
          "200": {
            "description": "Catalog of categories and scenarios",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/CatalogResponse" } }
            }
          }
        }
      }
    },
    "/api/pricing": {
      "get": {
        "tags": ["Billing"],
        "operationId": "getPricing",
        "summary": "Retrieve micro-USD operation pricing, Creem prepaid credit packs, and $0-on-422/error policy",
        "responses": {
          "200": {
            "description": "Pricing schedule and Creem SKUs",
            "content": {
              "application/json": { "schema": { "type": "object", "additionalProperties": true } }
            }
          }
        }
      }
    },
    "/api/holidays": {
      "get": {
        "tags": ["Catalog"],
        "operationId": "getHolidays",
        "summary": "Query multi-jurisdiction statutory holidays and leap-year info for (jurisdiction, year)",
        "parameters": [
          { "name": "jurisdiction", "in": "query", "required": false, "schema": { "type": "string", "default": "US", "enum": ["US", "UK", "SG", "HK", "EU"] } },
          { "name": "year", "in": "query", "required": false, "schema": { "type": "integer", "default": 2026 } }
        ],
        "responses": {
          "200": {
            "description": "Statutory holiday list for the requested jurisdiction and year",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HolidaysResponse" } } }
          },
          "422": {
            "description": "Invalid jurisdiction or year rejected with $0 billing",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error422Response" } } }
          }
        }
      },
      "post": {
        "tags": ["Catalog"],
        "operationId": "postHolidays",
        "summary": "Query multi-jurisdiction statutory holidays and leap-year info via JSON body",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HolidayCalendarRequest" } } }
        },
        "responses": {
          "200": {
            "description": "Statutory holiday calendar result",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HolidaysResponse" } } }
          },
          "422": {
            "description": "Invalid year or jurisdiction rejected with $0 billing",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error422Response" } } }
          }
        }
      }
    },
    "/api/balance": {
      "get": {
        "tags": ["Billing"],
        "operationId": "getTenantBalance",
        "summary": "Check prepaid micro-USD balance for a tenant via X-Tenant-Id, X-API-Key, or ?tenant_id=",
        "parameters": [
          { "name": "tenant_id", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Tenant micro-USD balance and call counters",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          }
        }
      }
    },
    "/api/plan": {
      "post": {
        "tags": ["Planning"],
        "operationId": "computeCriticalPathPlan",
        "summary": "Compute forward/backward CPM critical path, Gantt bars, bottlenecks, parallel checklist, expedite ROI, and holiday roll-forwards",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/PlanRequest" } }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic CPM critical-path schedule",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/PlanResponse" } }
            }
          },
          "422": {
            "description": "DAG cycle, invalid ISO date, or unsupported jurisdiction — strictly $0 billed (charged_micros == 0)",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Error422Response" } }
            }
          }
        }
      }
    },
    "/api/compare": {
      "post": {
        "tags": ["Planning"],
        "operationId": "compareExpediteAndScenarios",
        "summary": "Compare standard vs expedited vs multi-scenario critical-path options with cost/days-saved ROI",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/CompareRequest" } }
          }
        },
        "responses": {
          "200": {
            "description": "Side-by-side standard vs expedited and ranked scenario comparison",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          },
          "422": {
            "description": "Invalid parameters rejected with $0 billing",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error422Response" } } }
          }
        }
      }
    },
    "/api/portal-check": {
      "post": {
        "tags": ["Portals"],
        "operationId": "checkOfficialPortal",
        "summary": "Safe read-only official public portal status probe backed by 7d-30d cross-tenant archive cache ($0 on error)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/PortalCheckRequest" } }
          }
        },
        "responses": {
          "200": {
            "description": "Public portal reachability, latency, and cache-tier billing result",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PortalCheckResponse" } } }
          },
          "422": {
            "description": "Unknown portal_id or invalid input rejected with $0 billing",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error422Response" } } }
          }
        }
      }
    },
    "/api/batch": {
      "post": {
        "tags": ["Planning"],
        "operationId": "runBatchPlans",
        "summary": "Concurrent multi-jurisdiction timeline batch evaluation bounded by max_budget_micros ($0 per failed/422 item)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/BatchRequest" } }
          }
        },
        "responses": {
          "200": {
            "description": "Aggregated batch results with per-item $0-on-error enforcement",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          },
          "422": {
            "description": "Malformed batch payload rejected with $0 billing",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error422Response" } } }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": ["MCP"],
        "operationId": "invokeMcpJsonRpc",
        "summary": "Native JSON-RPC 2.0 MCP endpoint (initialize, ping, tools/list, tools/call)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["jsonrpc", "method"],
                "properties": {
                  "jsonrpc": { "type": "string", "const": "2.0" },
                  "id": { "type": ["string", "integer", "null"] },
                  "method": { "type": "string", "enum": ["initialize", "notifications/initialized", "ping", "tools/list", "tools/call"] },
                  "params": { "type": "object", "additionalProperties": true }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 MCP response",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          }
        }
      }
    },
    "/webhooks/creem": {
      "post": {
        "tags": ["Billing"],
        "operationId": "handleCreemWebhook",
        "summary": "Constant-time HMAC-SHA256 verified Creem webhook ingress (CREEM_WEBHOOK_SECRET env var)",
        "parameters": [
          {
            "name": "creem-signature",
            "in": "header",
            "required": true,
            "schema": { "type": "string" },
            "description": "HMAC-SHA256 hex signature of raw request body using CREEM_WEBHOOK_SECRET"
          }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
        },
        "responses": {
          "200": {
            "description": "Webhook verified and idempotently settled in SQLite WAL ledger",
            "content": { "application/json": { "schema": { "type": "object", "additionalProperties": true } } }
          },
          "401": { "description": "Invalid or missing creem-signature HMAC-SHA256 digest" },
          "503": { "description": "CREEM_WEBHOOK_SECRET not configured in environment" }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": ["Catalog"],
        "operationId": "getOpenApiSpec",
        "summary": "OpenAPI 3.1.0 machine-readable specification",
        "responses": { "200": { "description": "OpenAPI JSON" } }
      }
    },
    "/llms.txt": {
      "get": {
        "tags": ["Catalog"],
        "operationId": "getLlmsTxt",
        "summary": "AI agent discovery index for clock.fastmesh.dev",
        "responses": { "200": { "description": "Plain text llms.txt index" } }
      }
    },
    "/skill.md": {
      "get": {
        "tags": ["Catalog"],
        "operationId": "getSkillMd",
        "summary": "Agent integration manual for REST, /mcp, and QuickJS",
        "responses": { "200": { "description": "Markdown integration manual" } }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "HealthResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "service": { "type": "string" },
          "version": { "type": "string" },
          "port": { "type": "integer" },
          "uptime_s": { "type": "number" },
          "disclaimer": { "type": "string" },
          "categories": { "type": "array", "items": { "type": "string" } },
          "scenario_count": { "type": "integer" },
          "ledger": { "type": "object", "additionalProperties": true },
          "archive_cache": { "type": "object", "additionalProperties": true },
          "external_spend_cap_micros": { "type": "integer" }
        }
      },
      "CatalogResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "categories": { "type": "array", "items": { "type": "string" } },
          "scenarios_by_category": { "type": "object", "additionalProperties": true },
          "total_scenarios": { "type": "integer" }
        }
      },
      "HolidaysResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "jurisdiction": { "type": "string" },
          "year": { "type": "integer" },
          "is_leap_year": { "type": "boolean" },
          "holidays": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": { "type": "string" },
                "name": { "type": "string" },
                "weekday": { "type": "string" }
              }
            }
          }
        }
      },
      "HolidayCalendarRequest": {
        "type": "object",
        "properties": {
          "jurisdiction": { "type": "string", "default": "US", "enum": ["US", "UK", "SG", "HK", "EU"] },
          "year": { "type": "integer", "default": 2026 }
        }
      },
      "PlanRequest": {
        "type": "object",
        "properties": {
          "category": { "type": "string", "enum": ["entity_tax_psp", "ip_trademark_patent", "product_compliance", "trade_logistics", "digital_infra"] },
          "scenario": { "type": "string", "description": "Built-in scenario ID (e.g., us_de_llc_ein_psp, uspto_office_action, matson_fast_boat)" },
          "jurisdiction": { "type": "string", "enum": ["US", "UK", "SG", "HK", "EU"] },
          "start_date": { "type": "string", "description": "ISO YYYY-MM-DD forward start date" },
          "target_date": { "type": "string", "description": "ISO YYYY-MM-DD backward launch deadline" },
          "expedite": { "type": "boolean", "default": false },
          "daily_delay_cost_usd": { "type": "number", "default": 0.0 },
          "tasks": { "type": "array", "items": { "type": "object", "additionalProperties": true }, "description": "Optional custom DAG tasks" },
          "tenant_id": { "type": "string" },
          "try_now": { "type": "boolean", "default": true }
        }
      },
      "PlanResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "plan_id": { "type": "string" },
          "category": { "type": "string" },
          "scenario_id": { "type": "string" },
          "jurisdiction": { "type": "string" },
          "schedule_mode": { "type": "string", "enum": ["forward", "backward"] },
          "anchor_date": { "type": "string" },
          "estimated_start_date": { "type": "string" },
          "estimated_completion_date": { "type": "string" },
          "critical_path": { "type": "array", "items": { "type": "string" } },
          "critical_task_ids": { "type": "array", "items": { "type": "string" } },
          "project_duration_days": { "type": "integer" },
          "wall_calendar_days": { "type": "integer" },
          "serial_total_days": { "type": "integer" },
          "parallel_critical_days": { "type": "integer" },
          "days_saved_by_parallelism": { "type": "integer" },
          "parallelism_speedup_pct": { "type": "number" },
          "tasks": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "gantt_bars": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "incompressible_bottlenecks": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "parallelizable_prep_checklist": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "statutory_roll_forwards": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "expedite_comparison": { "type": "object", "additionalProperties": true },
          "official_portals": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
          "charged_micros": { "type": "integer" },
          "billed_micros": { "type": "integer" },
          "billing_mode": { "type": "string" },
          "receipt_sha256": { "type": "string" },
          "disclaimer": { "type": "string" }
        }
      },
      "CompareRequest": {
        "type": "object",
        "properties": {
          "scenario": { "type": "string" },
          "category": { "type": "string" },
          "jurisdiction": { "type": "string" },
          "start_date": { "type": "string" },
          "target_date": { "type": "string" },
          "daily_delay_cost_usd": { "type": "number", "default": 0.0 },
          "scenarios": { "type": "array", "items": { "type": "string" } }
        }
      },
      "PortalCheckRequest": {
        "type": "object",
        "required": ["portal_id"],
        "properties": {
          "portal_id": { "type": "string" },
          "max_age_s": { "type": "integer" },
          "no_cache": { "type": "boolean", "default": false },
          "verify": { "type": "boolean", "default": false },
          "confirm": { "type": "boolean", "default": false },
          "tenant_id": { "type": "string" }
        }
      },
      "PortalCheckResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "portal_id": { "type": "string" },
          "portal_name": { "type": "string" },
          "portal_url": { "type": "string" },
          "status_code": { "type": "integer" },
          "reachable": { "type": "boolean" },
          "latency_ms": { "type": "number" },
          "cache_status": { "type": "string" },
          "is_repeat_tenant": { "type": "boolean" },
          "ttl_s": { "type": "integer" },
          "charged_micros": { "type": "integer" },
          "upstream_cost_micros": { "type": "integer" },
          "receipt_sha256": { "type": "string" },
          "disclaimer": { "type": "string" }
        }
      },
      "BatchRequest": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/PlanRequest" }
          },
          "max_budget_micros": { "type": "integer" },
          "max_workers": { "type": "integer", "default": 4 },
          "tenant_id": { "type": "string" }
        }
      },
      "Error422Response": {
        "type": "object",
        "required": ["ok", "error_code", "error", "charged_micros", "billed_micros"],
        "properties": {
          "ok": { "type": "boolean", "const": false },
          "error_code": { "type": "string" },
          "error": { "type": "string" },
          "charged_micros": { "type": "integer", "const": 0 },
          "billed_micros": { "type": "integer", "const": 0 },
          "disclaimer": { "type": "string" }
        }
      }
    }
  }
}
