Metadata-Version: 2.4
Name: irides-prism
Version: 0.2.0
Summary: Static and AI-assisted repository scanner generating standardized database.md and technology.md overviews for Irides.
Author-email: Gian Andrea Sechi <me@gianandreasechi.com>
License: Apache-2.0
Project-URL: Source Code, https://github.com/GianAndreaSechi/irides/tree/main/packages/prism
Project-URL: Homepage, https://www.gianandreasechi.com
Keywords: database,technology,discovery,markdown,irides,documentation,monorepo
Classifier: Development Status :: 4 - Beta
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 :: Software Development :: Documentation
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: irides-core>=0.2.0
Requires-Dist: PyYAML>=6.0
Provides-Extra: sql
Requires-Dist: sqlglot>=25.0; extra == "sql"
Provides-Extra: ai
Requires-Dist: irides-core[ai]; extra == "ai"
Provides-Extra: git
Requires-Dist: httpx>=0.27; extra == "git"
Provides-Extra: all
Requires-Dist: sqlglot>=25.0; extra == "all"
Requires-Dist: irides-core[ai]; extra == "all"
Requires-Dist: httpx>=0.27; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"

# Irides Prism (`irides-prism`)

Satellite package for **Irides** that scans local directories, monorepos, or Git repositories to generate standardized, at-a-glance **`database.md`** and **`technology.md`** overview documents.

## Features

- **Zero-AI static baseline**: Works out of the box without any LLM API key.
  - **`database.md`**: Summarizes database types, instances, sanitized hosts, and involved tables (`read` / `write` / `ddl`) across SQL, dbt, ORM models (SQLAlchemy, Django, Prisma, TypeORM, JPA), migrations, `docker-compose`, Terraform, `.env.example`, and `irides.yaml`.
  - **`technology.md`**: Summarizes prominent technologies (AWS S3, Databricks, Spark, Delta Lake, dbt, Airflow, Kafka, Redis, Docker, Terraform, FastAPI, etc.) grouped by category.
- **Optional 2-stage AI refinement (`--use-ai`)**: Runs only when explicitly requested and an API key (`LITELLM_API_KEY` or provider key) is present, degrading cleanly to static results on missing key or errors.
- **Monorepo & multi-folder support**: Scans one or multiple local non-Git directories or auto-detects subprojects in monorepos (`--mode auto|single|monorepo`, `--project-dir`).
- **Git & Pull Requests (`--open-pr`)**: Commits, pushes, and opens or updates GitHub Pull Requests (`GITHUB_TOKEN`) and GitLab Merge Requests (`GITLAB_TOKEN`).

## Ownership & Overwrite Policy

Every file generated by `irides-prism` includes YAML frontmatter with `managed_by: irides`.

- **New file**: Created atomically (`database.md` / `technology.md`).
- **Existing Irides-managed file (`managed_by: irides`)**: Overwritten completely when content changes (`unchanged` otherwise, ensuring no spurious Git diffs).
- **Existing unmanaged file (including case-insensitive matches such as `DATABASE.MD`)**: Skipped with a `conflict_unmanaged` error (non-zero CLI exit code) to prevent accidental loss of hand-written documentation. Pass **`--force`** to explicitly overwrite unmanaged files.

## Installation

```bash
# Standalone installation (includes the `irides-prism` binary; no `irides-cli` or `redis` required):
pip install irides-prism
# Optional extras:
pip install "irides-prism[sql,ai,git]"
# Or install together with the unified Irides CLI (`irides prism`):
pip install "irides-cli[prism]"
```

## Standalone CLI (`irides-prism`) & Unified CLI (`irides prism`)

You can run Prism either directly via its standalone `irides-prism` binary (no `irides-cli` needed) or as a plugin under `irides prism` when `irides-cli` is installed:

```bash
# Standalone binary (identical flags apply to `irides prism ...`)
irides-prism ./service-a ./service-b
irides-prism ./my-monorepo --mode monorepo --output-dir ./irides/prism
irides-prism ./my-repo --dry-run
irides-prism ./my-repo --force
irides-prism ./my-repo --use-ai
irides-prism https://github.com/org/repo.git --open-pr --base-branch main
```

## Python Library Usage (Standalone)

You can also use `irides-prism` directly from Python without starting Redis, the API, or `irides-cli`:

```python
from irides_prism import PrismOptions, run_prism

report = run_prism(
    PrismOptions(
        paths=["./my-monorepo"],
        mode="monorepo",
        output_dir="./irides/prism",
    )
)
print(report.ok, [t.project for t in report.targets])
```

## CLI Options Reference (`irides-prism` / `irides prism`)

```bash
# Scan current folder or multiple non-Git folders
irides prism ./service-a ./service-b

# Scan a monorepo (dry run)
irides prism ./my-monorepo --mode monorepo --dry-run

# Overwrite pre-existing non-Irides DATABASE.MD / technology.md
irides prism ./my-repo --force

# Optional AI refinement
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

# Aggregate multiple repos into a shared central vault alongside `irides describe` (`STORAGE_EXPORT_DIR=./irides/database`)
irides prism https://github.com/org/service-a.git --output-dir ./irides/prism
```

## Central Vault Layout (`--output-dir`)

When `--output-dir` is set, outputs are always nested by project so multiple runs never overwrite each other:
- Single project: `<output_dir>/<project>/database.md` and `technology.md`
- Monorepo subproject: `<output_dir>/<repo>/<subproject>/database.md` and `technology.md`

When combined with `--open-pr`, files are written inside the repository for the Pull Request **and** mirrored into `--output-dir`.

## Unified Metadata & OKF Export Pipeline

Like `irides describe`, the `irides-prism` / `irides prism` CLI (and `worker_prism`) delegates canonical JSON persistence and derived **Markdown + OKF v0.2** catalog exports to Irides' shared `FileMetadataStore` and `FileArtifactStore`:

- Canonical JSON: `STORAGE_METADATA_DIR/prism/{project}/database.json` and `technology.json`
- Derived Markdown: `STORAGE_EXPORT_DIR/markdown/prism/{project}/database.md` and `technology.md`
- Derived OKF v0.2: `STORAGE_EXPORT_DIR/okf/catalog/prism/{project}/database.md` and `technology.md` (indexed alongside DB tables in `okf/catalog/index.md`)

Opt out cleanly with `--no-save-metadata`, `--no-export-markdown`, or `--no-export-okf`.

## Git Authentication & PR Permissions (`--open-pr`)

When cloning private repositories or running with `--open-pr`, set one of:
- **`GITHUB_TOKEN`** (GitHub clones and PRs)
- **`GITLAB_TOKEN`** (GitLab clones and MRs)
- **`IRIDES_GIT_TOKEN`** (generic fallback token for either provider)

For **GitHub Fine-grained Personal Access Tokens**:
- Under **Repository access**, select **`Only select repositories`** (choosing the target repo) or **`All repositories`** (*Public repositories* only grants read-only access).
- Under **Repository permissions**, grant **`Contents: Read and write`** (required for `git push`) and **`Pull requests: Read and write`** (required to open/update PRs).
- Alternatively, a **Classic PAT** with the **`repo`** scope provides both permissions.

## Downstream Catalog Enrichment

Once `irides describe` and `irides prism` have populated `STORAGE_METADATA_DIR`, run **`irides-enrichment`** (`irides enrich`) to link `database.md` files to catalog DB tables with bidirectional `used_by` backlinks and PK/FK wikilinks. See [packages/enrichment/README.md](https://github.com/GianAndreaSechi/irides/blob/main/packages/enrichment/README.md).

## Async Platform Integration

For asynchronous multi-repository scans triggered via REST API (`POST /api/v1/prism/scan`) or MCP (`enqueue_prism_scan`), see [services/worker_prism/README.md](https://github.com/GianAndreaSechi/irides/blob/main/services/worker_prism/README.md), [services/api/README.md](https://github.com/GianAndreaSechi/irides/blob/main/services/api/README.md), and [infra/README.md](https://github.com/GianAndreaSechi/irides/blob/main/infra/README.md).
