Skip to content

Comments

Add configurable env tail append option#76

Merged
riatzukiza merged 3 commits intodevfrom
append-env-context-config
Nov 22, 2025
Merged

Add configurable env tail append option#76
riatzukiza merged 3 commits intodevfrom
append-env-context-config

Conversation

@riatzukiza
Copy link
Collaborator

Summary

  • add appendEnvContext plugin config defaulting from CODEX_APPEND_ENV_CONTEXT and pass through transforms
  • ensure request/cache transforms use config flag instead of ambient env and document the behavior
  • make related tests explicit about env tail handling and add coverage for config/env defaults

Testing

  • pnpm test test/cache-e2e.test.ts test/request-transformer.test.ts test/plugin-config.test.ts

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

Summary by CodeRabbit

  • New Features
    • Introduced appendEnvContext configuration option to control whether environment and file context is appended to prompts. Users can configure this setting via the CODEX_APPEND_ENV_CONTEXT environment variable or directly in the plugin configuration file.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Replaces static DEFAULT_CONFIG with a getDefaultConfig() that reads CODEX_APPEND_ENV_CONTEXT and adds an appendEnvContext flag to PluginConfig; propagates that flag through request transformation (transformRequestForCodex → transformRequestBody → transformInputForCodex) and updates tests to pass the flag explicitly.

Changes

Cohort / File(s) Summary
Config & types
lib/config.ts, lib/types.ts
Replaced static DEFAULT_CONFIG with private getDefaultConfig() that derives appendEnvContext from process.env.CODEX_APPEND_ENV_CONTEXT. Added appendEnvContext?: boolean to PluginConfig. Updated config merge/fallback paths to use getDefaultConfig() and merge nested logging against defaults.
Request transformation plumbing
lib/request/fetch-helpers.ts, lib/request/request-transformer.ts
Renamed _pluginConfigpluginConfig. Added appendEnvContext to TransformRequestOptions and passed appendEnvContext explicitly through transformRequestForCodextransformRequestBodytransformInputForCodex; fall back to process.env.CODEX_APPEND_ENV_CONTEXT === "1" only when option is undefined.
Tests / helpers
test/cache-e2e.test.ts, test/plugin-config.test.ts, test/request-transformer.test.ts
Tests updated to import PluginConfig, pass explicit appendEnvContext to helpers, and stop manipulating env var directly. Added setup/teardown to preserve/restore CODEX_APPEND_ENV_CONTEXT. Updated expectations to include appendEnvContext.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Test / Caller
    participant Fetch as fetch-helpers
    participant Transformer as request-transformer
    participant Config as config

    Caller->>Fetch: transformRequestForCodex(body, pluginConfig?)
    Fetch->>Config: (if needed) getDefaultConfig()
    Fetch->>Fetch: resolve appendEnvContext = pluginConfig?.appendEnvContext ?? envFlag
    Fetch->>Transformer: transformRequestBody(body, { appendEnvContext })
    Transformer->>Transformer: transformInputForCodex(..., appendEnvContext)
    alt appendEnvContext == true
        Transformer->>Transformer: append env/files context to prompt tail
    else
        Transformer->>Transformer: omit env/files tail
    end
    Transformer-->>Fetch: transformed body
    Fetch-->>Caller: final transformed request
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Attention areas:
    • lib/request/request-transformer.ts — verify both codex-mode and other branches correctly use the passed appendEnvContext and only fall back to the env var where intended.
    • lib/config.ts — ensure getDefaultConfig() is used everywhere and nested logging merges against defaults.logging.
    • Tests — confirm env var setup/teardown preserves isolation and updated expectations match merged defaults.

Possibly related PRs

  • Allow config overrides for logging and silence warn toasts #68 — touches lib/config.ts and PluginConfig merge/merge-default logic; likely overlapping changes to config-merging behavior.
  • Device/stealth #20 — modifies request transform plumbing and PluginConfig propagation; related to passing flags through transformRequestForCodex/transformRequestBody.
  • Release #29 — updates request/config plumbing and pluginConfig usage in transform functions; likely intersects with these changes.

Poem

A tiny flag slips into the config seam,
From env it wakes, then joins the pipeline stream.
Prompts get fuller when the toggle says so,
Tests now pass it on—no secrets left to show. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a configurable environment tail append option (appendEnvContext) throughout the codebase.
Description check ✅ Passed The description clearly relates to the changeset, outlining the addition of appendEnvContext config, its integration through transforms, and testing approach.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch append-env-context-config

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39fca57 and bc28004.

📒 Files selected for processing (1)
  • test/cache-e2e.test.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/cache-e2e.test.ts (1)
lib/types.ts (2)
  • RequestBody (159-181)
  • PluginConfig (6-30)
🔇 Additional comments (1)
test/cache-e2e.test.ts (1)

33-37: LGTM! Helper function correctly threads through the config.

The runTransform helper now accepts and propagates the pluginConfig parameter to transformRequestForCodex, with a sensible default of { appendEnvContext: false }.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fea41f3 and 39fca57.

⛔ Files ignored due to path filters (1)
  • spec/append-env-context-config.md is excluded by none and included by none
📒 Files selected for processing (7)
  • lib/config.ts (3 hunks)
  • lib/request/fetch-helpers.ts (2 hunks)
  • lib/request/request-transformer.ts (4 hunks)
  • lib/types.ts (1 hunks)
  • test/cache-e2e.test.ts (3 hunks)
  • test/plugin-config.test.ts (7 hunks)
  • test/request-transformer.test.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
test/request-transformer.test.ts (1)
lib/request/request-transformer.ts (1)
  • transformRequestBody (101-159)
test/plugin-config.test.ts (1)
lib/config.ts (1)
  • loadPluginConfig (32-74)
test/cache-e2e.test.ts (1)
lib/types.ts (1)
  • PluginConfig (6-30)
lib/request/fetch-helpers.ts (1)
lib/types.ts (1)
  • PluginConfig (6-30)
lib/config.ts (3)
lib/types.ts (1)
  • PluginConfig (6-30)
lib/utils/file-system-utils.ts (1)
  • safeReadFile (56-62)
lib/logger.ts (1)
  • logWarn (160-162)
🪛 GitHub Check: Lint & Typecheck
test/cache-e2e.test.ts

[warning] 1-1:
'beforeEach' is defined but never used. Allowed unused vars must match /^_/u

🔇 Additional comments (11)
lib/types.ts (1)

20-24: LGTM! Clean addition of the configuration field.

The appendEnvContext field is properly typed and documented. The JSDoc clearly communicates the default source and purpose.

test/request-transformer.test.ts (1)

717-791: LGTM! Tests are now explicit and deterministic.

The tests now explicitly control the appendEnvContext flag rather than relying on environment variable side effects. This improves test clarity and reduces the risk of test pollution.

test/cache-e2e.test.ts (1)

33-47: LGTM! Clean integration of pluginConfig.

The runTransform helper now accepts a pluginConfig parameter with a sensible default (appendEnvContext: false) that ensures deterministic test behavior. The config is correctly propagated to transformRequestForCodex.

test/plugin-config.test.ts (2)

32-53: LGTM! Proper test isolation.

The setup and teardown properly save and restore the CODEX_APPEND_ENV_CONTEXT environment variable to prevent test pollution.


102-119: LGTM! Good coverage of appendEnvContext behavior.

The new tests verify both:

  1. Environment-based default when config is missing
  2. Config override takes precedence over environment variable

This ensures the priority order is correct: explicit config > environment variable > default.

lib/request/fetch-helpers.ts (1)

120-167: LGTM! Correct priority order for appendEnvContext.

The appendEnvContext flag is sourced with the correct priority: pluginConfig?.appendEnvContext (explicit config) falls back to process.env.CODEX_APPEND_ENV_CONTEXT === "1" (environment variable). The parameter rename from _pluginConfig to pluginConfig correctly indicates it's now being used.

lib/config.ts (2)

12-22: LGTM! Clean refactor to enable runtime configuration.

Converting DEFAULT_CONFIG from a static constant to the getDefaultConfig() function allows the appendEnvContext default to be derived from the environment variable at runtime. The function returns a fresh object each time, avoiding shared state issues.


32-73: LGTM! All call sites updated correctly.

The migration from DEFAULT_CONFIG to getDefaultConfig() is complete and consistent throughout the function. The merge logic correctly uses defaults.logging in all paths (default, success, and error).

lib/request/request-transformer.ts (3)

25-30: LGTM! Clear documentation of the new option.

The appendEnvContext option is properly documented and typed in TransformRequestOptions.


37-99: LGTM! Clean propagation of appendEnvContext flag.

The appendEnvContext flag is correctly added to transformInputForCodex and used to control the environment/context reattachment logic. The implementation maintains backward compatibility while enabling explicit control.


101-159: LGTM! Correct fallback pattern for appendEnvContext.

The transformRequestBody function correctly computes appendEnvContext with the proper priority: options.appendEnvContext (explicit) falls back to process.env.CODEX_APPEND_ENV_CONTEXT === "1" (environment variable). The flag is then threaded through to transformInputForCodex.

riatzukiza and others added 2 commits November 21, 2025 20:34
…tion or class'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@riatzukiza riatzukiza merged commit 208d9d2 into dev Nov 22, 2025
15 of 16 checks passed
@riatzukiza riatzukiza deleted the append-env-context-config branch November 22, 2025 16:48
github-actions bot added a commit that referenced this pull request Nov 22, 2025
@riatzukiza riatzukiza mentioned this pull request Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant