Metadata-Version: 2.4
Name: daygent
Version: 0.3.0
Summary: Static lineage and impact analysis for modern data + AI repositories.
Author: Emmanuel Onwubuya
Maintainer: Emmanuel Onwubuya
License-Expression: MIT
Project-URL: Homepage, https://github.com/emyrael/daygent
Project-URL: Repository, https://github.com/emyrael/daygent
Project-URL: Issues, https://github.com/emyrael/daygent/issues
Keywords: lineage,impact-analysis,dbt,sql,fastapi,langgraph,llm,vector-store,static-analysis,cli
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.7
Requires-Dist: PyYAML>=6.0
Requires-Dist: rich>=13.7
Requires-Dist: sqlglot>=25.0
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Provides-Extra: release
Requires-Dist: build>=1.2; extra == "release"
Requires-Dist: twine>=5.0; extra == "release"
Dynamic: license-file

# Daygent

Local-first static lineage and blast-radius analysis for modern data + AI repositories.

Daygent reads source files on disk and builds a dependency graph you can inspect, query, and share as JSON, Mermaid, or a fully offline HTML viewer. It answers questions like:

- What depends on this table or dbt model?
- Which API routes could change if this function changes?
- What is downstream of this dataset?
- Which agents, LLMs, or vector collections sit on this path?

It does **not** connect to warehouses, APIs, vector databases, or cloud accounts. It does **not** execute scanned code, resolve environment variables, or phone home.

## Interactive graph viewer

<p align="center">
  <img src="assets/daygent-graph.png" alt="Daygent interactive dependency graph viewer" width="100%">
</p>

Explore dependencies visually, inspect nodes and edges, filter by technology, and trace upstream/downstream impact — fully offline.

```bash
daygent scan .
daygent graph --html --open
```

## Why it exists

Data + AI codebases mix SQL, dbt, Python services, FastAPI, LangGraph, LLM constructors, and HTTP clients. Runtime catalogs and vendor consoles only see what already ran. Daygent maps what the **source** statically declares, so you can review impact before you ship.

## How it works

```text
Repository
   ↓
Scanner (walk files, skip junk)
   ↓
Technology parsers (all matching parsers run)
   ↓
Candidate graph
   ↓
Relevance scope  ←  scan broadly, graph narrowly
   ↓
.daygent/graph.json
   ↓
daygent graph  |  daygent impact  |  HTML viewer
```

Parsers may see every function in a file. The final graph keeps **data/AI lineage**: tables, dbt models, LLMs, vector stores, HTTP hosts, LangGraph nodes, and the connector code that joins them. Unrelated helpers such as `format_date()` stay out unless they sit on that lineage.

## Graph convention

**A → B means B depends on A.** Impact walks with the arrows. Upstream lineage walks against them.

```text
raw.users
   ↓
stg_users
   ↓
user_features
```

Changing `raw.users` can affect everything below it.

## Supported technologies

Static detection only:

| Area | What Daygent reads |
| --- | --- |
| Python | modules, functions, local calls, imports |
| SQL | table lineage via sqlglot, including CTEs |
| dbt | `ref()` / `source()` anywhere in Jinja (`{% set %}`, macro arguments, `~` concatenation), `config(alias=...)`; `target/manifest.json` is merged automatically when present (no dbt CLI) |
| FastAPI | routes, handlers, `include_router` |
| LangGraph | literal `add_node` / `add_edge` |
| LLM constructors | ChatOpenAI, Anthropic, Azure, … when the model is a literal |
| Embeddings | OpenAI / HuggingFace / SentenceTransformer constructors |
| Vector stores | Qdrant, Pinecone, Weaviate, Chroma, FAISS, PGVector |
| External HTTP | literal `https://host/...` URLs |
| PySpark | table reads/writes (`spark.table`, `read.table`, `saveAsTable`, `writeTo`) and literal `spark.sql` |
| Databricks DLT / Lakeflow | pipeline declarations (`@dlt.table`, `@dp.materialized_view`, `dlt.read`, …) |
| Embedded SQL in Python | literal SQL in `execute` / `text(...)` style calls |
| pandas | literal `read_sql` / `read_sql_query` / `read_sql_table` |
| Django | basic ORM model lineage, `objects.raw`, explicit `Meta.db_table` |
| SQLAlchemy | basic model/table lineage, `select`/`query`, literal `text()`, explicit `__tablename__` |

No live vendor, database, Spark session, Django setup, SQLAlchemy engine, or network calls.

### Static name resolution

Table names and SQL are resolved when they are knowable from source alone, including across files:

```python
# etl/settings.py
RAW = "raw"
ORDERS = f"{RAW}.orders"

# etl/job.py
from etl.settings import ORDERS        # also `import etl.settings as s; s.ORDERS`
spark.table(ORDERS)                    # → raw.orders
spark.table("{}.events".format(RAW))   # → raw.events
```

Imported, re-exported, relative-imported and module-attribute constants all resolve, as do `+`, f-strings and `.format()` built from them. A name bound twice at module level is never guessed.

Names that only exist at runtime (`os.getenv("TABLE")`, function arguments, `spark.sql(query)` over an unknown string) are **not** guessed either. They are recorded as **gaps** instead, so a missing edge is visible rather than silent:

```bash
daygent gaps
```

```text
Data references: 287 of 312 resolved, 25 dynamic (names only known at runtime)

Location            Kind         Expression
etl/jobs.py:28      table_read   os.environ['SOURCE_TABLE']
etl/jobs.py:29      sql          f'SELECT * FROM raw.partitioned_{run_date}'
models/mart.sql:4   dbt_ref      ref(name)
```

## Install

Requires Python 3.11+.

```bash
pip install daygent
```

With uv:

```bash
uv tool install daygent
```

One-off:

```bash
uvx daygent --help
```

## Quick Start

```bash
daygent scan .
daygent graph --html --open
daygent impact <node>
```

From a clone (contributors):

```bash
git clone https://github.com/emyrael/daygent.git
cd daygent
python3.11 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
```

## Commands

```bash
daygent scan .
daygent graph
daygent graph --json
daygent graph --mermaid
daygent graph --html --open
daygent impact <node>
daygent gaps
```

`scan` writes `.daygent/graph.json` (gitignored). `graph` and `impact` read that artifact. If it is missing, the CLI tells you to scan first.

Useful flags:

```bash
daygent scan . --verbose
daygent scan . --full          # keep code outside data/AI lineage too
daygent graph --html --include-source --open
daygent impact stg_users --depth 2 --json
```

`--include-source` is opt-in. Default HTML never embeds repository file contents; it still shows the file, line and evidence for every node and edge, plus a hint to re-run with the flag. With the flag, nodes show their definition (up to 25 lines from where it starts) and edges show the lines around the call that created them. The viewer banners: *This HTML contains source-code excerpts.*

## Config is optional

No `daygent.yml` is required. Empty or missing `include` means repository-wide discovery, then lineage scoping.

```yaml
# daygent.yml — optional overrides only
exclude:
  - migrations/**
  - generated/**
output: .daygent/graph.json
```

Built-in skips include `.venv`, `node_modules`, `graphify-out`, `.cursor`, and `*.egg-info`.

## HTML viewer

`daygent graph --html --open` writes a self-contained `.daygent/graph.html`:

- opens on **asset lineage**: tables, dbt models, pipeline datasets, routes, and vector stores, with Python functions and temp views contracted into single edges
- **Show implementation details** reveals the full detailed graph; nothing is ever deleted from it
- connected pipelines are laid out left to right and packed into rows, so unrelated flows sit side by side instead of stacking into one tall column
- filtering by one or more types keeps the matching nodes **plus their lineage neighbours** (switch to `Show matches only` for the strict view)
- **Focus lineage** reduces the canvas to the selected node's connected flow
- search centers the first match and keeps its context; Enter cycles matches
- clicking a contracted edge lists the hops it hides, e.g. `via load_orders() → tmp_orders → clean_orders()`, with the file, line and code of each hop
- a **dynamic references** panel lists every gap from `daygent gaps`, so missing lineage is never invisible
- `bronze.*` / `silver.*` / `gold.*` appear as grouping labels only where the name actually contains them; they never create edges
- no CDN, no `fetch`, no telemetry

## Local-first guarantees

- Fully offline after install
- No telemetry
- No runtime network calls from Daygent itself
- No warehouse / vector-store / API credentials
- No secret or environment resolution
- Scan warnings do not print file bodies

## Cross-stack lineage

Daygent statically connects lineage across SQL, dbt, PySpark, Databricks DLT/Lakeflow, Python data access, Django/SQLAlchemy, AI/vector infrastructure, LangGraph, and FastAPI where dependencies can be resolved from source. A change to an `app.requests` dbt source can reach a FastAPI route through hops such as:

```text
app.requests → raw_data_request → subscription_info → gold_subscription_metrics
  → v_subscription_metrics → silver.subscription_features → gold.customer_360
  → app.subscription_snapshot → load_subscription_documents() → build_subscription_index()
  → subscription_rag → retrieve → generate → POST /ask
```

Those hops do not require imports across data boundaries. The dbt layer does not need to import the pipeline and the pipeline does not need to import the Django app; Daygent reconciles asset identity across the repository, so the `gold_subscription_metrics` written by dbt and the one read by `spark.read.table(...)` are a single node.

## Known limitations (v0.3)

- Spark temp views resolve within the declaring module only. A view created in one file and consumed in another is not linked.
- Asset identity merges only on provable evidence: a dbt manifest relation, an exact qualified relation name, or a unique unqualified dbt model name. A schema-qualified table never collapses onto a bare model with the same basename, so genuinely ambiguous names stay separate nodes.
- Arbitrary runtime reflection is unsupported: `getattr`, dynamic imports, monkeypatching, and dependency injection do not produce edges.
- Full symbolic DataFrame propagation is not attempted; only deterministic same-function assignment forms are tracked.
- Runtime-constructed table names and SQL are not resolved; they are reported by `daygent gaps`. Constants resolve across modules only at module level and through static imports; class attributes and function return values are not followed.
- `execute()` over a bare variable is not reported as a gap, because it is as likely a query-builder statement as SQL text.
- dbt custom schemas (`config(schema=...)`) are recorded but not used for identity, since `generate_schema_name` decides the real schema; `alias` is used.
- Loop unrolling covers literal `dict`/`list`/`tuple` constants with `.items()`, `.keys()`, `.values()`, or direct iteration, up to 64 entries. Anything computed at runtime is skipped.
- DataFrame dataflow is same-function and assignment-level: `df = spark.read.table(...)`, `df = df.transform(...)`, `df.write...`, `df.createOrReplaceTempView(...)`. There is no symbolic execution.
- Cross-file Python calls resolve only through static imports. Dynamic dispatch, class instantiation, and attribute chains deeper than one level are not resolved.
- If a name is both a logical `@dlt.view` and a genuinely physical table elsewhere, the logical declaration wins and the two collapse into one node.
- No Spark plan analysis, Databricks workspace inspection, Django setup/import, or SQLAlchemy metadata reflection.
- Isolated Python helpers and unrelated health routes are omitted by design (scoping).
- dbt compile and warehouse introspection are out of scope.
- Default HTML does not ship source code.

The golden fixtures at `tests/fixtures/golden_mixed_stack/`, `tests/fixtures/python_data_stack/`, `tests/fixtures/dlt_sensor_pipeline/`, and `tests/fixtures/static_resolution/` lock this behavior.

## Roadmap

- Real-repository testing beyond fixtures

## License

MIT. See [LICENSE](LICENSE).

## Contribute

See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, parser contracts, and test rules.
