plans/2025-09-12-forge-dump-autoopen-env-var-v2.md
Implement environment variable control for the auto-open functionality of HTML dumps in the Forge CLI by integrating the FORGE_DUMP_AUTO_OPEN environment variable directly into the Environment service. The feature will be accessible via self.api.environment().auto_open_dump and should default to false (disabled) and only auto-open when explicitly set to true or 1.
Based on the GitHub issue (#1201) analysis and updated requirements:
/dump html automatically opens files in the Linux browseropen::that() call in ui.rs:739Current Implementation Location: crates/forge_main/src/ui.rs:721-740
Environment Service Architecture: The codebase uses a layered service architecture:
Environment struct in crates/forge_domain/src/env.rs:18 contains configuration fieldsEnvironmentInfra trait in crates/forge_infra/src/env.rs:107-108 handles environment variable accesscrates/forge_infra/src/env.rs:39-71self.api.environment() provides access to Environment structAccess Pattern: The desired self.api.environment().auto_open_dump pattern requires adding the field to the Environment struct and parsing logic to the infrastructure layer.
Task 1: Add auto_open_dump field to Environment struct
crates/forge_domain/src/env.rs:54 (add field after existing configuration fields)pub auto_open_dump: bool field to Environment structderive_setters::SettersTask 2: Add environment variable parsing in infrastructure layer
crates/forge_infra/src/env.rs:39-71 (in the get() method)FORGE_DUMP_AUTO_OPEN environment variable using existing parse_env helperfalse when variable is not set (maintains backward compatibility for new users)Task 3: Update UI dump method to use Environment service
crates/forge_main/src/ui.rs:721-740open::that() call with conditional logicself.api.environment().auto_open_dump to determine if auto-open should occurTask 4: Add user feedback for disabled auto-open
Task 5: Document environment variable in README.md
README.md:376-382 (add to existing "Tool Configuration" section)Task 6: Create comprehensive test coverage
crates/forge_infra/src/env.rs:269-511 (following existing test patterns)serial_test::serialTask 7: Verify integration and behavior
FORGE_DUMP_AUTO_OPEN is integrated into Environment serviceself.api.environment().auto_open_dump patternBreaking Change Risk for Existing Users
Environment Service Integration Complexity
Boolean Parsing Inconsistencies
parse_env helper and document supported values clearly in README.API Access Pattern Changes
self.api.environment() pattern is already established and widely used in the UI layer.Direct Environment Variable Check in UI
get_env_var()Service Method Approach
should_auto_open_dump() method to environment serviceWorkflow-level Configuration
Environment Struct Field Addition:
// In crates/forge_domain/src/env.rs
#[derive(Clone, Debug, Setters)]
pub struct Environment {
// existing fields...
pub auto_open_dump: bool,
}
Environment Variable Parsing:
// In crates/forge_infra/src/env.rs get() method
let auto_open_dump = parse_env::<bool>("FORGE_DUMP_AUTO_OPEN").unwrap_or(false);
Environment {
// existing field assignments...
auto_open_dump,
}
UI Integration:
// In crates/forge_main/src/ui.rs dump methods
if self.api.environment().auto_open_dump {
open::that(path.as_str()).ok();
} else {
// Provide user feedback about file location
}
README Documentation Pattern:
<details>
<summary><strong>Tool Configuration</strong></summary>
Configuring the tool calls settings:
```bash
# .env
FORGE_TOOL_TIMEOUT=300 # Maximum execution time in seconds for a tool (default: 300)
FORGE_DUMP_AUTO_OPEN=false # Automatically open dump files in browser (default: false)
This plan follows established architectural patterns in the Forge codebase while providing the requested self.api.environment().auto_open_dump access pattern and comprehensive documentation.