Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ requires-python = ">=3.11, <3.15"

dependencies = [
"pydantic>=2,<3",
"rich>=14,<15",
]

[dependency-groups]
Expand Down
24 changes: 24 additions & 0 deletions src/aignostics_foundry_core/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ This file provides an overview of all modules in `aignostics_foundry_core`, thei

| Module | Purpose | Description |
|--------|---------|-------------|
| **console** | Themed terminal output | Module-level `console` object (Rich `Console`) with colour theme and `_get_console()` factory |
| **health** | Service health checks | `Health` model and `HealthStatus` enum for tree-structured health status |

## Module Descriptions

<!-- For each module, document its purpose, features, dependencies, and usage. -->

### console

**Themed Rich console for structured terminal output**

- **Purpose**: Provides a module-level `console` object pre-configured with a colour theme for consistent, styled terminal output across all Foundry components
- **Key Features**:
- `console` — module-level `Console` singleton, ready to use
- Colour theme: `success` (green), `info` / `logging.level.info` (purple4), `warning` (yellow1), `error` (red1), `debug` (light_cyan3)
- `AIGNOSTICS_CONSOLE_WIDTH` env var — overrides console width (defaults to Rich's auto-detect, 80 in non-TTY environments)
- `legacy_windows=False` — modern Windows terminal support
- **Location**: `aignostics_foundry_core/console.py`
- **Dependencies**: `rich>=13`

### health

**Tree-structured health status for service health checks**
Expand Down Expand Up @@ -47,12 +61,22 @@ This file provides an overview of all modules in `aignostics_foundry_core`, thei
┌──────────────┴──────────────┐
│ aignostics_foundry_core │
├─────────────────────────────┤
│ console │
│ health │
└─────────────────────────────┘
```

## Usage Examples

```python
from aignostics_foundry_core import console

# Print with theme styles
console.print("[success]Done![/success]")
console.print("[warning]Caution: retrying...[/warning]")
console.print("[error]Failed to connect.[/error]")
```

```python
from aignostics_foundry_core.health import Health, HealthStatus

Expand Down
5 changes: 4 additions & 1 deletion src/aignostics_foundry_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
"""Foundational infrastructure for Foundry components."""
"""Foundational infrastructure for Foundry components.

We do NOT export any of the public APIs of the Foundry components here; see docs/decisions/0002-module-structure.md.
"""
31 changes: 31 additions & 0 deletions src/aignostics_foundry_core/console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Themed rich console."""

import os

from rich.console import Console
from rich.theme import Theme


def _get_console() -> Console:
"""Get a themed rich console.

The console width can be set via the AIGNOSTICS_CONSOLE_WIDTH environment variable.

Returns:
Console: The themed rich console.
"""
return Console(
theme=Theme({
"logging.level.info": "purple4",
"debug": "light_cyan3",
"success": "green",
"info": "purple4",
"warning": "yellow1",
"error": "red1",
}),
width=int(os.environ.get("AIGNOSTICS_CONSOLE_WIDTH", "0")) or None,
legacy_windows=False, # Modern Windows (10+) doesn't need width adjustment
)


console = _get_console()
43 changes: 43 additions & 0 deletions tests/aignostics_foundry_core/console_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Tests for console module."""

import importlib
import sys

import pytest
from rich.console import Console

from aignostics_foundry_core.console import console

EXPECTED_THEME_KEYS = ["success", "info", "warning", "error", "debug", "logging.level.info"]


class TestConsole:
"""Tests for the themed rich console module."""

@pytest.mark.unit
def test_console_is_console_instance(self) -> None:
"""Module-level console is a rich.console.Console instance."""
assert isinstance(console, Console)

@pytest.mark.unit
@pytest.mark.sequential
def test_console_default_width(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Module-level console has Rich's default width (80) when env var is not set."""
monkeypatch.delenv("AIGNOSTICS_CONSOLE_WIDTH", raising=False)
reloaded = importlib.reload(sys.modules["aignostics_foundry_core.console"])
assert reloaded.console.width == 80

@pytest.mark.unit
@pytest.mark.sequential
def test_console_custom_width(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Module-level console uses width from AIGNOSTICS_CONSOLE_WIDTH env var."""
monkeypatch.setenv("AIGNOSTICS_CONSOLE_WIDTH", "100")
reloaded = importlib.reload(sys.modules["aignostics_foundry_core.console"])
assert reloaded.console.width == 100

@pytest.mark.unit
def test_console_theme_contains_expected_keys(self) -> None:
"""Console can render text with all required theme style names without error."""
for key in EXPECTED_THEME_KEYS:
style = console.get_style(key)
assert style is not None, f"Theme style '{key}' should be defined on the console."
6 changes: 5 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading