Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

Summary

Centralizes all environment variable access in @outfitter/config with Zod validation, eliminating scattered biome-ignore comments and providing type-safe env access.

Problem

12 biome-ignore comments across the codebase due to conflict between:

  • TypeScript's noPropertyAccessFromIndexSignature (requires process.env["KEY"])
  • Biome's useLiteralKeys (prefers process.env.KEY)

Solution

Single centralized access point with proper validation:

import { env, getEnvBoolean } from "@outfitter/config";

// Static access (parsed once at module load)
console.log(env.NODE_ENV);  // "development" | "test" | "production"
console.log(env.HOME);       // string | undefined

// Dynamic access (for runtime-changing values like in tests)
if (getEnvBoolean("NO_COLOR")) {
  // disable colors
}

Changes

New in @outfitter/config

  • portSchema — Port validation (1-65535) with coercion
  • booleanSchema — String to boolean ("true"/"1" → true)
  • optionalBooleanSchema — Optional boolean handling
  • parseEnv<T>() — Generic schema-based env parsing
  • getEnvBoolean() — Dynamic runtime env reads
  • env — Pre-parsed typed environment object
  • 17 new tests

Updated @outfitter/ui

  • Uses getEnvBoolean() for terminal detection
  • Removed 3 biome-ignore comments

Benefits

  • One biome-ignore instead of 12 scattered
  • Runtime validation — fails fast with clear errors
  • Type coercion — strings become proper booleans
  • Type safetyenv.NODE_ENV typed as union

Test plan

  • 17 new env validation tests pass
  • All 38 UI tests pass
  • Typecheck passes
  • Lint passes

Fixes #22

🤖 Generated with Claude Code

Copy link
Contributor Author

galligan commented Jan 23, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd471f2f48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@galligan galligan force-pushed the p3-5/logging/redaction-default branch from de20be3 to 8e14398 Compare January 23, 2026 19:46
@galligan galligan force-pushed the p3-6/config/env-validation branch from 0f0a5d8 to 809e837 Compare January 23, 2026 19:46
@galligan galligan added the enhancement New feature or request label Jan 23, 2026
@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Centralizes environment variable access in @outfitter/config with Zod validation to eliminate 12 scattered biome-ignore comments throughout the codebase
  • Implements type-safe env schemas for ports (1-65535), booleans (string to boolean coercion), and a pre-parsed env object with proper typing
  • Adds comprehensive test coverage with 17 new tests and updates @outfitter/ui to use the new centralized env access functions

Important Files Changed

Filename Overview
packages/config/src/env.ts New centralized env validation module with critical type safety issue in the exported env object using unsafe type assertion
packages/config/src/index.ts Added env validation exports but left existing XDG functions using direct process.env access, creating inconsistency

Confidence score: 3/5

  • This PR requires careful review due to a critical type safety issue in the core environment validation module
  • Score lowered due to unsafe type assertion in env export that could mask validation errors and incomplete migration leaving direct process.env usage in XDG functions
  • Pay close attention to packages/config/src/env.ts line 210 where the type assertion could cause runtime issues

Sequence Diagram

sequenceDiagram
    participant User
    participant App as "Application Code"
    participant Config as "@outfitter/config"
    participant Zod as "Zod Validator"
    participant ProcessEnv as "process.env"
    
    User->>App: "Import env from @outfitter/config"
    App->>Config: "import { env }"
    Config->>Zod: "appEnvSchema.parse(process.env)"
    Zod->>ProcessEnv: "Read environment variables"
    ProcessEnv-->>Zod: "Raw string values"
    Zod->>Zod: "Transform and validate"
    Zod-->>Config: "Typed environment object"
    Config-->>App: "Pre-parsed env"
    App->>App: "Access typed env.NODE_ENV, env.NO_COLOR, etc."
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. packages/config/src/index.ts, line 106-107 (link)

    style: These direct process.env accesses should use the new centralized env system to eliminate biome-ignore comments. Are these XDG functions planned to be updated to use the centralized env access in a follow-up PR?

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@galligan galligan changed the base branch from p3-5/logging/redaction-default to graphite-base/42 January 23, 2026 21:18
@galligan galligan force-pushed the p3-6/config/env-validation branch from 809e837 to 213ff0b Compare January 23, 2026 21:20
@galligan galligan changed the base branch from graphite-base/42 to p3-5/logging/redaction-default January 23, 2026 21:20
@galligan
Copy link
Contributor Author

Updated color detection to treat NO_COLOR presence as disable and honor FORCE_COLOR numeric levels (0 disables, 1+ enables).

@galligan
Copy link
Contributor Author

Removed the unnecessary Env type assertion by wiring env through parseEnv(appEnvSchema) and dropped the now-unused lint suppression. Restacked and resubmitted.

@galligan galligan force-pushed the p3-6/config/env-validation branch from 27b3ce5 to fb1e133 Compare January 24, 2026 02:38
@galligan
Copy link
Contributor Author

Resubmitted after sync/restack. NO_COLOR/FORCE_COLOR handling and env typing fixes are in place on this branch; no further changes needed here.

@galligan
Copy link
Contributor Author

Addressed the Greptile note by deriving Env from the schema and typing the schema shape explicitly; env stays validated at module load. Updated the PR with the new commit.

Copy link
Contributor Author

galligan commented Jan 24, 2026

Merge activity

  • Jan 24, 1:54 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jan 24, 2:13 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jan 24, 2:13 PM UTC: @galligan merged this pull request with Graphite.

@galligan galligan changed the base branch from p3-5/logging/redaction-default to graphite-base/42 January 24, 2026 14:10
@galligan galligan changed the base branch from graphite-base/42 to main January 24, 2026 14:11
galligan and others added 4 commits January 24, 2026 14:12
- Add portSchema, booleanSchema, optionalBooleanSchema for env validation
- Add parseEnv() for generic schema-based env parsing
- Add getEnvBoolean() for dynamic runtime env reads
- Export typed env object with all common env vars
- Add 17 tests for env validation

Fixes #22

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@galligan galligan force-pushed the p3-6/config/env-validation branch from b9b892b to b12f9d2 Compare January 24, 2026 14:12
@galligan galligan merged commit 910b63b into main Jan 24, 2026
1 check passed
@galligan galligan deleted the p3-6/config/env-validation branch January 24, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(config): centralize environment variable access with Zod validation

2 participants