feat(install): merge user settings and turn off bundled skills
Copying the repo's settings.json over ~/.claude/settings.json would delete most of the operator's settings, so the installer now merges it. The merge and the new settings land together, so no overwriting installer ever deploys them. The merge runs before any other file is deployed, so an invalid settings file stops the install with nothing changed. It writes a complete temporary file and renames it, so a failure cannot truncate the user's settings. Impact: removing a setting from the repo no longer removes it from a machine that already has it. ADR: 0035 Refs: #280 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
1 parent
0f2d9ede68
commit
aa8319a1db
8 files changed
+191
-5
No files matched your search
@@ -7,10 +7,14 @@
|
||||
# Individual files — copied verbatim
|
||||
DEPLOY_FILES=(
|
||||
"providers/claude-code/CLAUDE.md:.claude/CLAUDE.md"
|
||||
"providers/claude-code/settings.json:.claude/settings.json"
|
||||
"core/AGENTS.md:.agents/AGENTS.md"
|
||||
)
|
||||
|
||||
# JSON files — merged into an existing destination; this repo's values win
|
||||
DEPLOY_JSON_MERGES=(
|
||||
"providers/claude-code/settings.json:.claude/settings.json"
|
||||
)
|
||||
|
||||
# Files that also need the executable bit set
|
||||
DEPLOY_EXECUTABLES=(
|
||||
"providers/claude-code/statusline-command.sh:.claude/statusline-command.sh"
|
||||
|
||||
+8
-1
@@ -7,6 +7,13 @@ source "$REPO_ROOT/scripts/deploy-manifest.sh"
|
||||
|
||||
echo "Installing from $REPO_ROOT..."
|
||||
|
||||
# First, so an unmergeable file stops the install before anything is deployed.
|
||||
for entry in "${DEPLOY_JSON_MERGES[@]}"; do
|
||||
dest="$HOME/${entry##*:}"
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
python3 "$REPO_ROOT/scripts/merge-json.py" "$REPO_ROOT/${entry%%:*}" "$dest"
|
||||
done
|
||||
|
||||
for entry in "${DEPLOY_FILES[@]}"; do
|
||||
dest="$HOME/${entry##*:}"
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
@@ -47,7 +54,7 @@ fi
|
||||
|
||||
echo ""
|
||||
echo "Deployed:"
|
||||
for entry in "${DEPLOY_FILES[@]}" "${DEPLOY_EXECUTABLES[@]}"; do
|
||||
for entry in "${DEPLOY_FILES[@]}" "${DEPLOY_JSON_MERGES[@]}" "${DEPLOY_EXECUTABLES[@]}"; do
|
||||
echo " ~/${entry##*:}"
|
||||
done
|
||||
for entry in "${DEPLOY_DIRS[@]}"; do
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Merge the JSON object in SRC into DEST. SRC wins; keys only DEST has are kept."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def merge(base, override):
|
||||
if not (isinstance(base, dict) and isinstance(override, dict)):
|
||||
return override
|
||||
merged = dict(base)
|
||||
for key, value in override.items():
|
||||
merged[key] = merge(base[key], value) if key in base else value
|
||||
return merged
|
||||
|
||||
|
||||
def merged_text(src_text, dest):
|
||||
with open(dest, encoding="utf-8") as f:
|
||||
existing = json.load(f)
|
||||
if not isinstance(existing, dict):
|
||||
raise ValueError("top level is not a JSON object")
|
||||
before = json.dumps(existing, indent=2, ensure_ascii=False)
|
||||
after = json.dumps(merge(existing, json.loads(src_text)), indent=2, ensure_ascii=False)
|
||||
return None if after == before else after + "\n"
|
||||
|
||||
|
||||
def replace_file(dest, text):
|
||||
# Renaming a complete temporary file over dest means a failure never truncates it.
|
||||
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(dest), prefix=".merge-json.")
|
||||
try:
|
||||
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
if os.path.exists(dest):
|
||||
shutil.copymode(dest, tmp)
|
||||
os.replace(tmp, dest)
|
||||
except BaseException:
|
||||
os.unlink(tmp)
|
||||
raise
|
||||
|
||||
|
||||
def main():
|
||||
src, dest_arg = sys.argv[1:]
|
||||
# Renaming over a symlink would replace the link, so write to its target.
|
||||
dest = os.path.realpath(dest_arg)
|
||||
with open(src, encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
try:
|
||||
if os.path.exists(dest):
|
||||
text = merged_text(text, dest)
|
||||
if text is not None:
|
||||
replace_file(dest, text)
|
||||
except (OSError, ValueError) as error:
|
||||
sys.exit(f"ERROR: cannot merge settings into {dest_arg}, left unchanged: {error}")
|
||||
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user