Skip to content

fix(installer): merge missing opencode config keys#156

Open
informaticadiaz wants to merge 2 commits intoGentleman-Programming:mainfrom
informaticadiaz:fix/151-preserve-opencode-config
Open

fix(installer): merge missing opencode config keys#156
informaticadiaz wants to merge 2 commits intoGentleman-Programming:mainfrom
informaticadiaz:fix/151-preserve-opencode-config

Conversation

@informaticadiaz
Copy link
Copy Markdown
Contributor

Summary

Fixes the installer behavior that could overwrite an existing user-managed ~/.config/opencode/opencode.json during the optional OpenCode setup flow.

This PR does two things:

  • preserves an existing opencode.json during the external OpenCode installer run
  • merges only missing keys from GentlemanOpenCode/opencode.json into an existing user config, keeping existing user values intact

Why

Upstream issue #151 reports that running Gentleman.Dots can overwrite an existing OpenCode config created by gentle-ai, which causes users to lose plugins, MCPs, orchestration settings, and other custom adjustments.

The current implementation should avoid destructive overwrites while still allowing fresh installs to receive the default OpenCode config.

Implementation

  • added preserveFileDuringOperation(...) to protect an existing file during mutation-prone external installer execution
  • added mergeJSONFileMissingKeys(...) and mergeMissingJSONKeys(...) for non-destructive missing-key merges on JSON object configs
  • updated the OpenCode setup path in installer/internal/tui/installer.go to:
    • preserve opencode.json during the external installer run
    • create the config on fresh installs
    • merge only missing keys on existing installs
  • added focused tests in installer/internal/tui/installation_steps_test.go for:
    • overwrite preservation
    • deletion preservation
    • no-existing-file behavior
    • missing-key JSON merge behavior

Validation

Executed in installer/:

gofmt -w internal/tui/installer.go internal/tui/installation_steps_test.go
go test ./internal/tui -run 'TestPreserveFileDuringOperation|TestMergeJSONFileMissingKeys'

Result:

ok   github.com/Gentleman-Programming/Gentleman.Dots/installer/internal/tui

I also ran:

go test ./internal/tui

That broader suite currently fails on clean main as well, with pre-existing failures tracked separately in my fork at informaticadiaz/Gentleman.Dots#3:

  • step-order expectations that appear desynchronized from SetupInstallSteps()
  • golden tests with platform-sensitive and/or stale expectations

I kept this PR focused on the opencode.json fix rather than mixing in unrelated test-suite repair work.

Scope notes

This change intentionally preserves existing user values and only injects missing keys from the repo default config. It does not attempt to rewrite or normalize user-defined values.

Closes #151

- fix(homebrew): use #!/bin/bash and NONINTERACTIVE=1 in interactive
  install script — /bin/sh on Debian/Ubuntu is dash, which causes
  "Bash is required to interpret this script." (closes Gentleman-Programming#137)

- fix(setshell): fallback to sudo usermod when chsh fails PAM auth —
  prevents crash in Docker and minimal Linux environments

- docs: add linux-install-fixes.md with root cause analysis, diffs,
  build/run commands, and test results
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.

Installation overwrites existing opencode.json configuration

1 participant