[PR #3023] feat(config): persist provider settings in a user config file #5561

Open
opened 2026-10-31 01:07:36 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3023
Author: @Jackzigen
Created: 10/13/2026
Status: 🔄 Open

Base: main ← Head: feat/user-config-persistence


📝 Commits (2)

  • 09a6e0e feat(config): persist provider settings in a user config file
  • a5db808 fix(config): address review findings on persistence safety and CLI surface

📊 Changes

7 files changed (+732 additions, -3 deletions)

View changed files

📝 scripts/rea.mjs (+22 -2)
📝 src/cli.ts (+44 -0)
📝 src/cli/utilityCommands.ts (+130 -0)
📝 src/cliCommandNames.ts (+1 -0)
➕ src/config/userConfig.ts (+252 -0)
📝 src/main.ts (+31 -1)
➕ tests/boundary/userConfig.test.ts (+252 -0)

📄 Description

Problem and expected behavior

Problem: Provider settings set once (GHIDRA_INSTALL_DIR etc.) revert on the next run, because every process rediscovers install paths from scratch. Reported in #3016.

Expected: Settings stick across runs for both CLI and MCP entry points, with env > config file > auto-detect precedence, and existing env-based workflows untouched.

Change and scope

  • New src/config/userConfig.ts: reads ~/.config/rea/rea.json (XDG XDG_CONFIG_HOME respected, platform-aware home resolution), validates keys against the known provider-setting allowlist, and merges values into the environment snapshot before parseConfig runs.
  • Precedence stays env > config file > auto-detect: the merge only fills keys that are unset in the environment.
  • Both entry points covered:
    • CLI: scripts/rea.mjs overlays the user config via the exported environmentWithUserConfig helper before createCli receives the environment.
    • MCP: src/main.ts merges the config into the environment snapshot before configuration parsing.
  • New rea config command as the write surface: list (default, prints effective value + source), --get NAME, --set NAME=VALUE (repeatable), --unset NAME (repeatable).

Follow the contribution scope: configuration persistence within existing boundaries — no target execution, injection, mutation, or protection recovery, so no maintainer scope decision is required (not applicable).

Contract and boundary impact

  • Semantic owner and earliest changed stage: config layer (src/config/userConfig.ts); CLI + MCP wiring downstream
  • Contribution scope fit and linked maintainer decision: read/write of a user-owned config file within existing boundaries; not applicable
  • CLI and MCP/tool-catalog contract: adds rea config subcommand (list/--get/--set/--unset); no existing command changed
  • Provider, bridge, target-format, or platform compatibility: platform-aware path resolution (POSIX/Windows), XDG respected
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details: not applicable
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: canonical product catalog re-verified (11/11) after regenerating the build artifact

Expected effects (check known effects; use documentation-only on its own).

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject into a process or target.
  • Modify a target or its environment.
  • Send data over a network.
  • Modify this repository or workspace files.
  • none / documentation-only

Compatibility, safety, and release

  • Breaking changes or migration steps: none — additive; env precedence preserved
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable — pure config-file handling
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: config file is user-owned (~/.config/rea/rea.json), keys validated against a known allowlist, unknown keys rejected; no secrets stored by this PR

Author readiness

Human owner: @Jackzigen

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Related issue is linked: Closes #3016.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Tests cover changed observable behavior and meaningful failure paths: tests/boundary/userConfig.test.ts (18 tests).
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output: rea config list/get/set/unset output with (env)/(config) source markers.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Local validation: npm run test:fast 427 files / 5560 passed / 0 failed; tsc --noEmit clean; oxfmt clean; end-to-end smoke on the bundled CLI confirms env-over-file precedence.


What

Provider settings set once (for example GHIDRA_INSTALL_DIR) currently revert on the next run because every process rediscovers install paths from scratch. This PR adds a user-owned config file so such settings stick, on both the CLI and MCP entry points.

Implementation

  • New src/config/userConfig.ts: reads ~/.config/rea/rea.json (XDG XDG_CONFIG_HOME respected, platform-aware home resolution), validates keys against the known provider-setting allowlist, and merges values into the environment snapshot before parseConfig runs.
  • Precedence stays env > config file > auto-detect: the merge only fills keys that are unset in the environment, so existing env-based workflows are untouched.
  • Both entry points covered:
    • CLI: scripts/rea.mjs now overlays the user config via the exported environmentWithUserConfig helper before createCli receives the environment.
    • MCP: src/main.ts merges the config into the environment snapshot before configuration parsing.
  • New rea config command as the write surface: list (default, prints effective value + source), --get NAME, --set NAME=VALUE (repeatable), --unset NAME (repeatable). Output marks whether each value comes from env or config.

Testing

  • New tests/boundary/userConfig.test.ts: 18 tests covering path resolution (XDG override, non-absolute fallback, Windows), JSON validation (unknown keys rejected), merge precedence (env wins, file fills gaps, invalid JSON surfaces a ConfigurationError), and write/unset round-trips on real temp directories (sorted keys, trailing newline, merge preserves other keys, unset on missing file is a no-op).
  • npm run test:fast: 427 files / 5560 passed / 0 failed.
  • tsc --noEmit clean; oxfmt clean; canonical product catalog re-verified (11/11) after regenerating the build artifact.
  • End-to-end smoke on the bundled CLI: config --set, then list shows (config); with the env var set the same list shows (env) and the file value is shadowed — precedence confirmed on the real binary.

Closes #3016


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/3023 **Author:** [@Jackzigen](https://github.com/Jackzigen) **Created:** 10/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/user-config-persistence` --- ### 📝 Commits (2) - [`09a6e0e`](https://github.com/morluto/rea/commit/09a6e0e571fc98c7e1a9a754b92a58cddf86a83e) feat(config): persist provider settings in a user config file - [`a5db808`](https://github.com/morluto/rea/commit/a5db808bb0fe9bf759c927240dd9fa92e6362cda) fix(config): address review findings on persistence safety and CLI surface ### 📊 Changes **7 files changed** (+732 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `scripts/rea.mjs` (+22 -2) 📝 `src/cli.ts` (+44 -0) 📝 `src/cli/utilityCommands.ts` (+130 -0) 📝 `src/cliCommandNames.ts` (+1 -0) ➕ `src/config/userConfig.ts` (+252 -0) 📝 `src/main.ts` (+31 -1) ➕ `tests/boundary/userConfig.test.ts` (+252 -0) </details> ### 📄 Description ## Problem and expected behavior **Problem**: Provider settings set once (`GHIDRA_INSTALL_DIR` etc.) revert on the next run, because every process rediscovers install paths from scratch. Reported in #3016. **Expected**: Settings stick across runs for both CLI and MCP entry points, with `env > config file > auto-detect` precedence, and existing env-based workflows untouched. ## Change and scope - New `src/config/userConfig.ts`: reads `~/.config/rea/rea.json` (XDG `XDG_CONFIG_HOME` respected, platform-aware home resolution), validates keys against the known provider-setting allowlist, and merges values into the environment snapshot before `parseConfig` runs. - Precedence stays **env > config file > auto-detect**: the merge only fills keys that are unset in the environment. - Both entry points covered: - CLI: `scripts/rea.mjs` overlays the user config via the exported `environmentWithUserConfig` helper before `createCli` receives the environment. - MCP: `src/main.ts` merges the config into the environment snapshot before configuration parsing. - New `rea config` command as the write surface: `list` (default, prints effective value + source), `--get NAME`, `--set NAME=VALUE` (repeatable), `--unset NAME` (repeatable). Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope): configuration persistence within existing boundaries — no target execution, injection, mutation, or protection recovery, so no maintainer scope decision is required (not applicable). ## Contract and boundary impact - Semantic owner and earliest changed stage: config layer (`src/config/userConfig.ts`); CLI + MCP wiring downstream - Contribution scope fit and linked maintainer decision: read/write of a user-owned config file within existing boundaries; not applicable - CLI and MCP/tool-catalog contract: adds `rea config` subcommand (`list`/`--get`/`--set`/`--unset`); no existing command changed - Provider, bridge, target-format, or platform compatibility: platform-aware path resolution (POSIX/Windows), XDG respected - Evidence, artifact, provenance, or reconstruction contract: none - Target selection, authority, upstream behavior, and cleanup details: not applicable - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: canonical product catalog re-verified (11/11) after regenerating the build artifact Expected effects (check known effects; use documentation-only on its own). - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject into a process or target. - [ ] Modify a target or its environment. - [ ] Send data over a network. - [ ] Modify this repository or workspace files. - [ ] none / documentation-only ## Compatibility, safety, and release - Breaking changes or migration steps: none — additive; env precedence preserved - Real Hopper/Ghidra, browser, or OS coverage: not applicable — pure config-file handling - Package or release metadata impact: none - Security, privacy, process, or containment review: config file is user-owned (`~/.config/rea/rea.json`), keys validated against a known allowlist, unknown keys rejected; no secrets stored by this PR ## Author readiness Human owner: @Jackzigen - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Related issue is linked: Closes #3016. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Tests cover changed observable behavior and meaningful failure paths: `tests/boundary/userConfig.test.ts` (18 tests). - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output: `rea config` list/get/set/unset output with `(env)`/`(config)` source markers. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. **Local validation**: `npm run test:fast` 427 files / 5560 passed / 0 failed; `tsc --noEmit` clean; `oxfmt` clean; end-to-end smoke on the bundled CLI confirms env-over-file precedence. --- ## What Provider settings set once (for example `GHIDRA_INSTALL_DIR`) currently revert on the next run because every process rediscovers install paths from scratch. This PR adds a user-owned config file so such settings stick, on both the CLI and MCP entry points. ## Implementation - New `src/config/userConfig.ts`: reads `~/.config/rea/rea.json` (XDG `XDG_CONFIG_HOME` respected, platform-aware home resolution), validates keys against the known provider-setting allowlist, and merges values into the environment snapshot before `parseConfig` runs. - Precedence stays **env > config file > auto-detect**: the merge only fills keys that are unset in the environment, so existing env-based workflows are untouched. - Both entry points covered: - CLI: `scripts/rea.mjs` now overlays the user config via the exported `environmentWithUserConfig` helper before `createCli` receives the environment. - MCP: `src/main.ts` merges the config into the environment snapshot before configuration parsing. - New `rea config` command as the write surface: `list` (default, prints effective value + source), `--get NAME`, `--set NAME=VALUE` (repeatable), `--unset NAME` (repeatable). Output marks whether each value comes from `env` or `config`. ## Testing - New `tests/boundary/userConfig.test.ts`: 18 tests covering path resolution (XDG override, non-absolute fallback, Windows), JSON validation (unknown keys rejected), merge precedence (env wins, file fills gaps, invalid JSON surfaces a ConfigurationError), and write/unset round-trips on real temp directories (sorted keys, trailing newline, merge preserves other keys, unset on missing file is a no-op). - `npm run test:fast`: 427 files / 5560 passed / 0 failed. - `tsc --noEmit` clean; `oxfmt` clean; canonical product catalog re-verified (11/11) after regenerating the build artifact. - End-to-end smoke on the bundled CLI: `config --set`, then list shows `(config)`; with the env var set the same list shows `(env)` and the file value is shadowed — precedence confirmed on the real binary. Closes #3016 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5561
No description provided.