feat(config): non-destructive opencode.jsonc.proposed sidecar (closes #8 batch item)
Completes the pi-devbox v1.1.4 "merge new defaults into preserved config" idea, adapted to opencode-devbox's env-generated, JSONC-with-comments config where an in-place merge would be destructive. generate-config.py keeps its "never touch an existing config" guarantee and adds a side-channel: when a live config exists, render the config it WOULD generate for the current env + image defaults and write it to a NON-loaded opencode.jsonc.proposed — but only when it differs from the live config; remove it once they match. opencode never loads .proposed files, so it is a pure manual-merge reference (e.g. surfacing a default MCP server added in a newer image). An unparseable live config surfaces the proposal rather than guessing equivalence. A one-line hint is logged on write. - render_config(): shared renderer so first-gen and proposed paths can't drift - _loads_jsonc(): string-aware //-comment strip (same approach as smoke-test; preserves https:// inside strings), raises on invalid JSON - write_proposed(): write-on-diff + stale removal + live untouched - smoke-test.sh: asserts write-on-diff, removal-on-match, live not clobbered - entrypoint-user.sh + module docstring: document the sidecar - CHANGELOG: moved from "Deferred" to "Added" Caveat (documented in the file header): the proposal reflects env + image defaults, so a diff may include the user's own past edits, not only new image defaults.
This commit is contained in:
@@ -306,6 +306,37 @@ if docker run --rm \
|
||||
else
|
||||
fail "$label: existing config was modified!"
|
||||
fi
|
||||
|
||||
# Proposed-config side-channel: when a config already exists, a NEWER default
|
||||
# config is surfaced as a NON-loaded opencode.jsonc.proposed (write-on-diff,
|
||||
# removed once the live config matches). The live config is never touched.
|
||||
label="generate-config writes .proposed only when config differs"
|
||||
if docker run --rm \
|
||||
-e OPENCODE_PROVIDER=anthropic \
|
||||
-e HOME=/tmp/home \
|
||||
--entrypoint="" \
|
||||
"$IMAGE" sh -c '
|
||||
set -e
|
||||
d=/tmp/home/.config/opencode
|
||||
mkdir -p "$d"
|
||||
gc=/usr/local/lib/opencode-devbox/generate-config.py
|
||||
# (a) differing existing config → proposed written, live NOT clobbered
|
||||
printf "{\n \"model\": \"old/model\"\n}\n" > "$d/opencode.jsonc"
|
||||
python3 "$gc" 2>/dev/null
|
||||
test -f "$d/opencode.jsonc.proposed"
|
||||
grep -q "old/model" "$d/opencode.jsonc"
|
||||
# (b) live matches defaults + stale proposed present → proposed removed
|
||||
rm -f "$d/opencode.jsonc" "$d/opencode.jsonc.proposed"
|
||||
python3 "$gc" 2>/dev/null
|
||||
cp "$d/opencode.jsonc" "$d/opencode.jsonc.proposed"
|
||||
python3 "$gc" 2>/dev/null
|
||||
test ! -f "$d/opencode.jsonc.proposed"
|
||||
echo ok
|
||||
' 2>/dev/null | grep -q ok; then
|
||||
pass "$label"
|
||||
else
|
||||
fail "$label: proposed-config behaviour incorrect"
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user