Metadata-Version: 2.4
Name: coreason_chronos
Version: 0.1.0
Summary: coreason-chronos
License: # The Prosperity Public License 3.0.0
         
         Contributor: CoReason, Inc.
         
         Source Code: https://github.com/CoReason-AI/coreason_chronos
         
         ## Purpose
         
         This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
         
         ## Agreement
         
         In order to receive this license, you have to agree to its rules.  Those rules are both obligations under that agreement and conditions to your license.  Don't do anything with this software that triggers a rule you can't or won't follow.
         
         ## Notices
         
         Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
         
         ## Commercial Trial
         
         Limit your use of this software for commercial purposes to a thirty-day trial period.  If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
         
         ## Contributions Back
         
         Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
         
         ## Personal Uses
         
         Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
         
         ## Noncommercial Organizations
         
         Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
         
         ## Defense
         
         Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
         
         ## Copyright
         
         The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
         
         ## Patent
         
         The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
         
         ## Reliability
         
         The contributor can't revoke this license.
         
         ## Excuse
         
         You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
         
         ## No Liability
         
         ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
License-File: LICENSE
License-File: NOTICE
Author: Gowtham A Rao
Author-email: gowtham.rao@coreason.ai
Requires-Python: >=3.11
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Dist: aiofiles (>=23.2.1,<24.0.0)
Requires-Dist: anyio (>=4.3.0,<5.0.0)
Requires-Dist: chronos-forecasting (>=2.2.2,<3.0.0)
Requires-Dist: click (>=8.3.1,<9.0.0)
Requires-Dist: dateparser (>=1.2.2,<2.0.0)
Requires-Dist: httpx (>=0.27.0,<0.28.0)
Requires-Dist: loguru (>=0.7.2,<0.8.0)
Requires-Dist: matplotlib (>=3.10.8,<4.0.0)
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
Requires-Dist: rapidfuzz (>=3.14.3,<4.0.0)
Requires-Dist: torch (>=2.9.1,<3.0.0)
Requires-Dist: transformers (>=4.57.3,<5.0.0)
Project-URL: Documentation, https://github.com/CoReason-AI/coreason_chronos
Project-URL: Homepage, https://github.com/CoReason-AI/coreason_chronos
Project-URL: Repository, https://github.com/CoReason-AI/coreason_chronos
Description-Content-Type: text/markdown

# coreason-chronos

Domain: Temporal Reasoning, Time-Series Forecasting, & Longitudinal Reconstruction

[![License](https://img.shields.io/badge/license-Prosperity%203.0-blue)](https://github.com/CoReason-AI/coreason_chronos)
[![CI](https://github.com/CoReason-AI/coreason_chronos/actions/workflows/ci.yml/badge.svg)](https://github.com/CoReason-AI/coreason_chronos/actions/workflows/ci.yml)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/CoReason-AI/coreason_chronos)
[![Docs](https://img.shields.io/badge/docs-PRD-informational)](docs/product_requirements.md)

## Overview

**coreason-chronos** is the specialized temporal processing unit of the CoReason ecosystem. It enables agents to reason about **When**, **How Long**, and **What's Next**.

Core Philosophy: *"Semantic time is fuzzy. Symbolic time is exact. We need both."*

It provides three critical capabilities:

1.  **Longitudinal Reconstruction:** Extracting events from unstructured text (e.g., "Patient started Taxol 3 weeks after surgery") and mapping them to a normalized absolute timeline.
2.  **Probabilistic Forecasting:** Predicting future events (e.g., "Clinical Trial Enrollment will hit 100% in 4.5 months +/- 2 weeks") using SOTA Time-Series Foundation Models.
3.  **Temporal Logic Validation:** Ensuring GxP compliance by validating temporal constraints (e.g., "Was the adverse event reported within the 24-hour statutory window?").

## Features

-   **The Timeline Extractor (The Historian):**
    -   Converts relative dates ("2 weeks later") to absolute timestamps.
    -   Resolves "anchored" events based on semantic proximity to reference events.
    -   Outputs structured `EventSeries` JSON.

-   **The Oracle (The Forecaster):**
    -   Leverages Foundation Time-Series Models (Amazon Chronos-T5).
    -   Zero-shot prediction capability for metrics like Patient Enrollment or Drug Inventory.
    -   Provides probabilistic forecasts (P90 confidence intervals).

-   **The Compliance Clock (The Validator):**
    -   Symbolic Rule Engine for regulatory checks.
    -   Validates constraints like `Report_Time <= Event_Time + 24_Hours`.

-   **The Causality Engine (The Sequencer):**
    -   Uses **Allen's Interval Algebra** to determine temporal plausibility of causal relationships.

## Installation

```bash
pip install coreason-chronos
```

## Usage

### 1. Initialize the Timekeeper

The `ChronosTimekeeper` is the main entry point for the library.

```python
from datetime import datetime, timezone
from coreason_chronos.agent import ChronosTimekeeper

# Initialize the agent
agent = ChronosTimekeeper()
```

### 2. Longitudinal Reconstruction (Timeline Extraction)

```python
text = "Patient was admitted on 2024-01-01. Symptoms started 2 days later."
reference_date = datetime(2024, 1, 1, tzinfo=timezone.utc)

events = agent.extract_from_text(text, reference_date)

for event in events:
    print(f"{event.timestamp}: {event.description}")
# Output:
# 2024-01-01 00:00:00+00:00: Patient was admitted...
# 2024-01-03 00:00:00+00:00: Derived from anchor...
```

### 3. Forecasting

```python
history = [10, 15, 20, 25, 30]  # Weekly enrollment
forecast = agent.forecast_series(history, prediction_length=5)

print(f"Median Forecast: {forecast.median}")
print(f"90% Confidence Interval: {forecast.lower_bound} - {forecast.upper_bound}")
```

### 4. Compliance Check

```python
from datetime import timedelta
from coreason_chronos.validator import MaxDelayRule

# Check if reporting was done within 24 hours
rule = MaxDelayRule(max_delay=timedelta(hours=24))

# ... (assuming target_event and ref_event are TemporalEvent objects)
# result = agent.check_compliance(target_event, ref_event, rule)

# if not result.is_compliant:
#     print(f"Compliance Violation! Drift: {result.drift}")
```

