orchestrata_tools.context.env_collector
Reference › orchestrata_tools › context › env_collector
This module inspects a project root for environment and infrastructure signals, for use in project_context. EnvCollector.collect returns an EnvContext. It lists which of .env, .envrc, .env.example and .env.local exist, records whether a Dockerfile or a compose file exists, and notes which of the directories incus, docker, kubernetes and terraform are present. From the process environment it copies only four variables if set: PYTHONPATH, VIRTUAL_ENV, POETRY_ACTIVE and UV_ACTIVE. The contents of env files are not read.
At a glance
| Source | src/orchestrata_tools/context/env_collector.py |
| Lines of code | 59 |
| Classes | 2 |
| Functions | 0 |
| Imports (internal) | none |
| Imported by | orchestrata_tools.context.project_context |
| Tests that import it | tests/test_orchestrata_tools.py |
Class diagram
Dependency diagram
API
Classes
EnvContext (dataclass)
Decorators: dataclass · Line 11
Collected environment configuration.
| Attribute | Type | Default |
|---|---|---|
env_vars |
dict[str, str] |
field(default_factory=dict) |
env_files |
list[str] |
field(default_factory=list) |
has_docker |
bool |
False |
has_docker_compose |
bool |
False |
infrastructure |
list[str] |
field(default_factory=list) |
EnvCollector
Line 21
Collect environment and infrastructure context.
| Method | Signature | Summary |
|---|---|---|
__init__ |
__init__(root_path: str | Path) |
|
collect |
collect() -> EnvContext |
Source
"""Collect environment variables and .env files for LLM context."""
from __future__ import annotations
import os
from dataclasses import dataclass, field
from pathlib import Path
@dataclass
class EnvContext:
"""Collected environment configuration."""
env_vars: dict[str, str] = field(default_factory=dict)
env_files: list[str] = field(default_factory=list)
has_docker: bool = False
has_docker_compose: bool = False
infrastructure: list[str] = field(default_factory=list)
class EnvCollector:
"""Collect environment and infrastructure context."""
def __init__(self, root_path: str | Path):
self.root = Path(root_path)
def collect(self) -> EnvContext:
ctx = EnvContext()
# Check for .env files
for pattern in [".env", ".envrc", ".env.example", ".env.local"]:
if (self.root / pattern).exists():
ctx.env_files.append(pattern)
# Check for Docker
ctx.has_docker = (self.root / "Dockerfile").exists()
ctx.has_docker_compose = (self.root / "docker-compose.yml").exists() or (
self.root / "docker-compose.yaml"
).exists()
# Check infrastructure
infra = []
if (self.root / "incus").exists():
infra.append("incus")
if (self.root / "docker").exists():
infra.append("docker")
if (self.root / "kubernetes").exists():
infra.append("kubernetes")
if (self.root / "terraform").exists():
infra.append("terraform")
ctx.infrastructure = infra
# Collect key env vars (non-sensitive)
for key in ["PYTHONPATH", "VIRTUAL_ENV", "POETRY_ACTIVE", "UV_ACTIVE"]:
val = os.environ.get(key)
if val:
ctx.env_vars[key] = val
return ctx