Metadata-Version: 2.4
Name: irides-cli
Version: 0.2.0
Summary: A command-line interface for discovering, inspecting, and managing structured database context for AI systems.
Author-email: Gian Andrea Sechi <me@gianandreasechi.com>
License: Apache-2.0
Project-URL: Source Code, https://github.com/GianAndreaSechi/irides/tree/main/packages/cli
Project-URL: Homepage, https://www.gianandreasechi.com
Keywords: database,introspection,cli,irides,schema
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: irides-core>=0.2.0
Provides-Extra: prism
Requires-Dist: irides-prism>=0.2.0; extra == "prism"
Provides-Extra: enrichment
Requires-Dist: irides-enrichment>=0.2.0; extra == "enrichment"
Provides-Extra: redis
Requires-Dist: irides-core[redis]>=0.2.0; extra == "redis"
Provides-Extra: all
Requires-Dist: irides-core[redis]>=0.2.0; extra == "all"
Requires-Dist: irides-prism>=0.2.0; extra == "all"
Requires-Dist: irides-enrichment>=0.2.0; extra == "all"

# Irides CLI (`irides-cli`)

Command-line interface for database introspection, repository discovery (`prism`), and catalog enrichment (`enrich`), built on `irides-core`. It does not require FastAPI, MCP, or the Redis worker.

## Structure

The CLI is organized by responsibility:

- `irides_cli/presentation/`: command definitions and `argparse` parsing;
- `irides_cli/controllers/`: maps command-line arguments to use cases;
- `irides_cli/dto/`: immutable, typed request DTOs;
- `irides_cli/services/`: live introspection and metadata operations using `irides-core`;
- `irides_cli/plugins.py`: entry-point plugin loader (`irides.cli_plugins`) for satellite packages such as `irides-prism` and `irides-enrichment`;
- `irides_cli/main.py`: composition root, JSON serialization, and process-level error handling.

## Installation

```bash
# Install from PyPI:
pip install irides-cli
# With Prism, Enrichment, and Redis support:
pip install "irides-cli[prism]"
pip install "irides-cli[enrichment]"
pip install "irides-cli[all]"

# Or editable install from this monorepo:
pip install -e ./packages/core -e ./packages/cli -e ./packages/prism -e ./packages/enrichment
```

## Quickstart & Configuration

Irides supports two ways to configure database targets:

### Option 1: Declarative Config File (`irides.yaml`) — Recommended
Generate a template configuration with:
```bash
irides init
```
This creates an `irides.yaml` file in the current directory:
```yaml
targets:
  my_postgres:
    type: postgres
    host: localhost
    port: 5432
    user: postgres
    password: "${PG_PASSWORD:-secret}"
    database: my_database

  local_sqlite:
    type: sqlite
    database: ./app.db
```
You can pass a custom config file anytime using `-c` / `--config-file`:
```bash
irides -c /path/to/my_config.yaml configurations
```

### Option 2: Environment Variables (`.env`)
You can initialize an environment template with:
```bash
irides init --format env
```
Or specify an explicit `.env` file via `-e` / `--env-file`:
```bash
irides -e /path/to/.env configurations
```

## Commands

```bash
# Initialize template configuration
irides init

# List configured database targets
irides configurations

# Test database connection
irides connect my_postgres

# List database instances
irides instances --target my_postgres

# List schemas in a database
irides schemas --target my_postgres --instance localhost

# List tables (supports --limit and --offset)
irides tables --target my_postgres --instance localhost --schema public --limit 50

# Introspect table schema
irides describe --target my_postgres --instance localhost --schema public --table orders
irides describe --target my_postgres --instance localhost --schema public --table orders --generate-ai-docs
irides describe --target my_postgres --instance localhost --schema public --table orders --no-export-okf
```

> **Note**: `--target` and `--config` are interchangeable aliases.
Omitting `--target`, `--instance`, `--schema`, or `--table` expands the scope, just like the corresponding API endpoints. Results are always written as JSON to stdout; errors are written to stderr. Add `--no-cache` to introspection commands to bypass Redis.

`describe` saves canonical JSON metadata and generates both **Markdown** and **Open Knowledge Format (OKF v0.2)** exports by default.

Available options for `describe`:
- `--generate-ai-docs`: generate domain summary and column descriptions via LiteLLM.
- `--no-save-metadata`: skip saving the canonical JSON metadata file (exports are still generated if enabled).
- `--only-if-changed`: skip writing if the schema is identical to the stored version.
- `--no-export-markdown`: disable the default Markdown export.
- `--no-export-okf`: disable the default OKF catalog bundle generation.
- `--no-preformat`: export full metadata instead of the essential deterministic record.
- `--save-markdown`: legacy compatibility flag for Markdown export.

Artifacts are persisted under `STORAGE_EXPORT_DIR` (default `storage/exports`):
- `storage/exports/markdown/database/{config}/{instance}/{schema}/{table}.md`
- `storage/exports/okf/catalog/database/{config}/{instance}/{schema}/{table}.md` (along with `storage/exports/okf/catalog/index.md`)

## Metadata

```bash
irides metadata instances
irides metadata databases db1.company.com
irides metadata tables db1.company.com production
irides metadata get db1.company.com production orders
irides metadata update db1.company.com production orders '{"owner":"data-team","tags":["billing"]}'
```

The CLI does not include async `scan` commands for DBs (those run via the API + `worker` using Redis Streams).

## Repository Discovery Plugin (`irides prism`)

When `irides-prism` is installed (e.g. `pip install "irides-cli[prism]"`), `irides` automatically exposes the `prism` subcommand via the `irides.cli_plugins` entry-point group to generate `database.md` and `technology.md`:

```bash
# Scan local non-Git directories or a monorepo
irides prism ./service-a ./service-b
irides prism ./my-monorepo --mode monorepo --output-dir ./irides/prism

# Preview without writing files or overwrite pre-existing unmanaged files
irides prism ./my-repo --dry-run
irides prism ./my-repo --force

# Optional AI refinement (when LITELLM_API_KEY / provider key is configured)
irides prism ./my-repo --use-ai

# Clone/update a Git repo and open or update a GitHub/GitLab PR
irides prism https://github.com/org/repo.git --open-pr --base-branch main
```

See [packages/prism/README.md](https://github.com/GianAndreaSechi/irides/blob/main/packages/prism/README.md) for details on the `managed_by: irides` ownership policy, Git PAT permissions, and `--output-dir` central vault structure.

## Catalog & Markdown Enrichment Plugin (`irides enrich`)

When `irides-enrichment` is installed (e.g. `pip install "irides-cli[enrichment]"` or `pip install "irides-cli[all]"`), `irides` also exposes the `enrich` subcommand to connect PK/FK wikilinks across same-instance DB tables, link `database.md` files to catalog tables, ensure base preformatters, and optionally generate AI TL;DRs:

```bash
irides enrich
irides enrich ./examples/sqlite_demo --use-ai
irides enrich --dry-run
```

See [packages/enrichment/README.md](https://github.com/GianAndreaSechi/irides/blob/main/packages/enrichment/README.md) for full details.

## Docker

The CLI Docker Compose service reads its configuration from `packages/cli/.env` and attaches to the shared `irides-net` network (`docker compose -f infra/docker-compose.infra.yml up -d` or `docker network create irides-net`).

### Tokens & Environment Variables
Put `GITHUB_TOKEN`, `GITLAB_TOKEN`, `IRIDES_GIT_TOKEN`, `LITELLM_API_KEY`, and `DB_TARGETS` in **`packages/cli/.env`** (or pass `--env-file .env` to `docker compose` to use the repository root `.env`). Inside the container, `packages/cli/.env` is also mounted at `/app/cli/.env` (usable via `irides -e /app/cli/.env ...`).

### One-Off Commands
```bash
docker compose -f packages/cli/docker-compose.yml build
docker compose -f packages/cli/docker-compose.yml run --rm irides-cli configurations
docker compose -f packages/cli/docker-compose.yml run --rm irides-cli -c /app/examples/sqlite_demo/irides.yaml describe --target demo_sqlite
```

### Keep Container Active (Persistent Dev Shell)
Because `packages/cli/Dockerfile` sets `ENTRYPOINT ["irides"]`, override the entrypoint to keep a container running across `describe`, `prism`, and `enrich`:
```bash
# Start persistent container in background
docker compose -f packages/cli/docker-compose.yml run -d --name irides-cli-dev --entrypoint sleep irides-cli infinity

# Enter an interactive shell or run commands directly
docker exec -it irides-cli-dev bash
docker exec irides-cli-dev irides -c /app/examples/sqlite_demo/irides.yaml describe --target demo_sqlite
docker exec irides-cli-dev irides prism /app/examples/sqlite_demo --output-dir /app/storage/prism
docker exec irides-cli-dev irides enrich --dry-run
docker exec irides-cli-dev irides enrich

# Stop and remove when done
docker rm -f irides-cli-dev
```

Or launch a temporary interactive shell that removes itself on exit:
```bash
docker compose -f packages/cli/docker-compose.yml run --rm --entrypoint bash irides-cli
```
