Skip to content

fix(setup): preserve env keys on /setup re-run via merge script#244

Merged
kyaulabs-bot merged 3 commits into
developfrom
fix/kyau-4df2-setup-preserve-user-config-keys
Jul 23, 2026
Merged

fix(setup): preserve env keys on /setup re-run via merge script#244
kyaulabs-bot merged 3 commits into
developfrom
fix/kyau-4df2-setup-preserve-user-config-keys

Conversation

@kyaulabs-bot

@kyaulabs-bot kyaulabs-bot commented Jul 23, 2026

Copy link
Copy Markdown
Member

📋 Summary

Fix #187/setup was silently destroying user-level env keys (env.deepseek_api_key, env.searxng_url) on every re-run by doing a destructive full-file jq -n ... > overwrite of ~/.config/opencode/setup.json. Replaced with an extracted .github/scripts/setup-write-user-config.sh that deep-merges user-scoped fields (identity, models, variants) onto the existing file, preserving unrelated keys.

📦 Changes by Phase

Phase A — Merge script extraction

  • New: .github/scripts/setup-write-user-config.sh — atomic deep-merge write; validates env vars, checks JSON validity, refuses to clobber on missing values or corrupt input
  • New: tests/Shell/setup_write_user_config_test.sh — 7 behavior tests (26 assertions)

Phase B — /setup §3 wiring

  • Modified: .opencode/commands/setup.md (§3) — replaced inline destructive jq block with script invocation + explanatory note
  • Modified: tests/Shell/setup_write_user_config_test.sh — appended Test 7 (regression guard: asserts wiring + absence of destructive overwrite)

✅ Verification

Gate Result
Shell tests 73/73 green (4 suites: 26 + 15 + 28 + 4)
Debug artifacts CLEAN
Secrets CLEAN (test fixtures use placeholder sk-KEEP-ME only)
File hygiene PASS (RCS headers + vim modelines on both new files)
@code-review GO (Ocr: skipped, Standards: 2 suggested non-blocking, Spec: 7/7, SAST: 0 findings)

📝 Commits (2 total, atomic & signed)

SHA Subject
ef10ecb fix(setup): extract user-config write to merge script
8119a04 fix(setup): wire merge script into /setup §3

🧪 Test Plan

  • bash tests/Shell/setup_write_user_config_test.sh — 26 passed, 0 failed
  • bash tests/Shell/setup_substitution_test.sh — 15 passed, 0 failed
  • bash tests/Shell/migrate_setup_test.sh — 28 passed, 0 failed
  • bash tests/Shell/script_executable_bits_test.sh — 4 passed, 0 failed
  • Manually seed a ~/.config/opencode/setup.json with an env block, re-run /setup with changed models, confirm env keys survive

kyau added 2 commits July 23, 2026 01:34
Replace the destructive inline jq -n ... > full-file overwrite in /setup
§3 with an extracted .github/scripts/setup-write-user-config.sh that
deep-merges user-scoped fields (identity, models, variants) onto the
existing ~/.config/opencode/setup.json, preserving env.deepseek_api_key
and env.searxng_url. Atomic write; refuses to clobber on missing values
or corrupt input.

Refs: #187
Authored-by: glm-5.2
Tested-by: deepseek-v4-pro
Signed-off-by: kyau <git@kyaulabs.com>
Replace the inline destructive jq -n ... > overwrite of
~/.config/opencode/setup.json in /setup §3 with a call to
setup-write-user-config.sh, and add a regression guard test asserting the
wiring stays safe. Completes the fix for the silent env-key wipe.

Fixes: #187
Authored-by: glm-5.2
Tested-by: deepseek-v4-pro
Signed-off-by: kyau <git@kyaulabs.com>

@kyau kyau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✔️ Approved by: @kyau

The new setup-write-user-config.sh was missing from the
quality-surface.manifest, causing the scaffold test reverse-parity
check to fail in CI (1 file in scope but not in manifest).

Refs: #187
Authored-by: glm-5.2
Tested-by: deepseek-v4-pro
Signed-off-by: kyau <git@kyaulabs.com>
@kyaulabs-bot
kyaulabs-bot merged commit 9579004 into develop Jul 23, 2026
6 checks passed
@kyaulabs-bot
kyaulabs-bot deleted the fix/kyau-4df2-setup-preserve-user-config-keys branch July 23, 2026 09:16
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.

/setup Overwrites User-Level setup.json, Destroying Keys

2 participants