fix(migration,profile): recipe resolves the clone root and fails closed before cp; find -mindepth 1; grep -F id match; local JSON on stdin; -L guard before the impeccable refresh

This commit is contained in:
bchanot committed 2026-11-02 12:21:10 +01:00
1 parent 08ae797ba5
commit 04635833a2
5 files changed
+43 -24

No files matched your search

+34 -17
View File
@@ -207,30 +207,47 @@ is the only one that removes a real directory (`make plugin` replaces
`skills-external/impeccable` on a refresh); steps 1 and 2 use `mv`, never
`rm -r`.
1. From the repo root. `git pull --autostash` (a plain `git pull` aborts
when `settings.json` is modified locally and the incoming commits touch
it; autostash keeps your UI writes), then restore the user-scope plugins
the old `profile.sh` had toggled. Never `git checkout -- settings.json`:
it would drop your UI writes.
1. From the clone root. `~/.claude` is a real directory of symlinks into
the clone, not the clone itself, so resolve the root first. `git pull
--autostash` (a plain `git pull` aborts when `settings.json` is modified
locally and the incoming commits touch it; autostash keeps your UI
writes), then restore the user-scope plugins the old `profile.sh` had
toggled. Never `git checkout -- settings.json`: it would drop your UI
writes.
```bash
cd ~/.claude
git pull --autostash
ep="$(mktemp)"; next="$(mktemp)"
git show HEAD:settings.json | jq .enabledPlugins > "$ep"
jq --slurpfile ep "$ep" '.enabledPlugins = $ep[0]' settings.json > "$next"
cp "$next" settings.json; rm -f "$ep" "$next"
root="$(dirname "$(readlink -f ~/.claude/settings.json)")" \
&& cd "$root" || exit 1
git pull --autostash \
&& ep="$(mktemp)" \
&& git show HEAD:settings.json | jq -e '.enabledPlugins | objects' \
> "$ep" \
&& next="$(mktemp)" \
&& jq --slurpfile ep "$ep" '.enabledPlugins = $ep[0]' settings.json \
> "$next" \
&& jq -e . "$next" >/dev/null && [ -s "$next" ] \
&& cp "$next" settings.json
rm -f "$ep" "$next"
```
Every command is chained with `&&` so that a failed step never reaches
`cp`, which writes through the symlink into the live tracked
`settings.json`. `jq -e '.enabledPlugins | objects'` fails when HEAD
holds no object (a null would wipe every plugin). `jq -e .` and `[ -s ]`
refuse an invalid or empty result (an empty file would drop the plugins,
the deny rules and the hooks).
2. Old layout. List the flat links first, then remove the links of
`skills-disabled/` and the links of `skills/` that are not kept
(model-router, darwin-skill, the seven superpowers, the agent-skills
trio). If `skills/impeccable` or `skills-disabled/impeccable` is a real
directory, `mv` it to `skills-external/impeccable` (never `rm`).
directory, `mv` it to `skills-external/impeccable` (never `rm`). Run it
from `$root` (step 1). The trailing slash and `-mindepth 1` keep `find`
from matching the start point, which is itself a symlink in `~/.claude`.
```bash
cd ~/.claude
find skills skills-disabled -maxdepth 1 -type l
cd "$root" || exit 1
find skills/ skills-disabled/ -mindepth 1 -maxdepth 1 -type l
mkdir -p skills-external
for d in skills skills-disabled; do
if [ -d "$d/impeccable" ] && [ ! -L "$d/impeccable" ] \
@@ -238,8 +255,8 @@ is the only one that removes a real directory (`make plugin` replaces
mv "$d/impeccable" skills-external/impeccable
fi
done
find skills-disabled -maxdepth 1 -type l -delete
find skills -maxdepth 1 -type l \
find skills-disabled/ -mindepth 1 -maxdepth 1 -type l -delete
find skills/ -mindepth 1 -maxdepth 1 -type l \
! -name model-router ! -name darwin-skill \
! -name observability-and-instrumentation \
! -name deprecation-and-migration ! -name ci-cd-and-automation \
@@ -250,7 +267,7 @@ is the only one that removes a real directory (`make plugin` replaces
rmdir skills-disabled; rm -f .active-profile
```
3. `make link` (link.sh no longer links the design and scroll skills flat),
3. From `$root`: `make link` (link.sh no longer links the design and scroll skills flat),
`make plugin` (fills `skills-external/`; impeccable ends in
`skills-external/impeccable`).
4. `~/.bashrc`: delete `dtach_claude()` and `alias cc='dtach_claude'` (the
@@ -1673,7 +1673,7 @@ MAJOR → change: user-scope residue `ui-ux-pro-max:false` (cor 6, rob 3) → Ta
MINOR → change: router canary measures nothing + typed long slash never routed (cor 12, rob 17) → C1 dropped, long rows unconditional, row → skill test (simp 6, cor 22a) · SC1003 / SC2088 / widths / PASS counts / .gitignore anchors / `.gitignore` not scanned by `--include` / `\.profile` pattern / Task 13 diff shape / onboard :608 pack / banner overflow / `make profile` scope / `-e .git` / Review Focus names (cor 13-21, 24, 25) → fixed in place · T8-real install dependency (rob 16) → `--installed` flag, WARN in `make test` · Task 1 pack left behind (rob 11) → OFF pack via `--settings` + trap · `alias cc` (rob 12) → doctor warn, guarded source line · SIGPIPE in detect_gstack (rob 15) → here-string · unused knobs (simp 7) → `DESIGN_GATE_REPO_OVERRIDE`, `PACKS :`, `CC_LIB_DIR` dropped.
Deferred, human-ack: none. Not done, said why: `.git/info/exclude` for `settings.local.json` (rob 14): onboarded projects ignore it already; the Claude Code write race is documented in `/profile`, not solved. Secret in `~/.bashrc:151` (rob 19, outside scope): reported to the user, no edit.
Deferred, human-ack: none. Not done, said why: `.git/info/exclude` for `settings.local.json` (rob 14): onboarded projects ignore it already; the Claude Code write race is documented in `/profile`, not solved. A hardcoded credential in a dotfile (rob 19, outside scope) was reported to the user (location withheld), no edit.
Lenses returned: correctness / robustness / simplicity.
+2 -1
View File
@@ -892,7 +892,8 @@ else
fi
# The CLI writes into skills/impeccable (through the ~/.claude/skills
# symlink); the copy lives in skills-external/, linked by pack-design.
cd "$REPO" && rm -rf skills-external/impeccable && mv "$IMP_SKILL_DIR" skills-external/impeccable
[ ! -L "$IMP_SKILL_DIR" ] && cd "$REPO" && rm -rf skills-external/impeccable \
&& mv "$IMP_SKILL_DIR" skills-external/impeccable
info "Per-project step, in the agent chat of each frontend project: /impeccable init"
info " (writes PRODUCT.md — the design context every impeccable verb reads)"
elif [ -f "$IMP_HOME/SKILL.md" ]; then
+4 -4
View File
@@ -204,16 +204,16 @@ cmd_set() {
require_name "$1" "$NAME_RE" "profile name"
f="$(profile_file "$1")"; [ -f "$f" ] || unknown_profile "$1"
require_project_root; cur="$(read_local)"
new="$(jq --argjson cur "$cur" \
new="$(jq --slurpfile p "$f" \
--argjson names "$(managed_connectors | as_json_list)" '
. as $p | $cur
. as $cur | $p[0] as $p
| .enabledPlugins = (($cur.enabledPlugins // {}) + $p.enabledPlugins)
| .deniedMcpServers = ([($cur.deniedMcpServers // [])[]
| select(.serverName as $s | ($names | index($s)) == null)]
+ ($p.deniedMcpServers // []))
| if (.deniedMcpServers | length) == 0 then del(.deniedMcpServers)
else . end
| if $p.model then .model = $p.model else . end' "$f")"
| if $p.model then .model = $p.model else . end' <<<"$cur")"
write_local "$new"
echo "profile $1 → $LOCAL_REL"; after_write_hint
}
@@ -251,7 +251,7 @@ cmd_toggle() { # $1 true|false, $2 pack or plugin spelling
local id cur new
require_name "$2" "$PACK_RE" "pack or plugin name"
id="$(resolve_id "$2")"
managed_ids | grep -qx -- "$id" \
managed_ids | grep -qxF -- "$id" \
|| die "unknown pack or plugin '$2' (known: $(managed_ids | tr '\n' ' '))"
require_project_root; cur="$(read_local)"
new="$(jq --arg id "$id" --argjson v "$1" \
+2 -1
View File
@@ -448,7 +448,8 @@ print(d.get('impeccable',{}).get('version','latest'))
if [ "$IMP_OK" = true ] && [ -f "$IMP_SKILL_DIR/SKILL.md" ]; then
IMP_SKILL_VER=$(sed -n 's/^version:[[:space:]]*//p' "$IMP_SKILL_DIR/SKILL.md" | head -1)
ok "impeccable refreshed (CLI ${IMP_VER:-latest}, skill ${IMP_SKILL_VER:-?})"
cd "$REPO" && rm -rf skills-external/impeccable && mv "$IMP_SKILL_DIR" skills-external/impeccable
[ ! -L "$IMP_SKILL_DIR" ] && cd "$REPO" && rm -rf skills-external/impeccable \
&& mv "$IMP_SKILL_DIR" skills-external/impeccable
else
warn "impeccable refresh failed (${IMP_FAIL:-no SKILL.md written}) — existing copy kept"
fi