-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync
More file actions
executable file
·186 lines (161 loc) · 6.64 KB
/
Copy pathsync
File metadata and controls
executable file
·186 lines (161 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
set -e
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
INSTALLED_FILE="$HOME/.claude/plugins/installed_plugins.json"
PLUGIN_KEY="tripod@tripod"
# ── Step 1: Read plugin version from manifest ────────────────────────────────
plugin_version=$(python3 -c "import json; print(json.load(open('$REPO_DIR/.claude-plugin/plugin.json'))['version'])")
# Current HEAD SHA for installed_plugins.json metadata
git_sha=$(git -C "$REPO_DIR" rev-parse HEAD 2>/dev/null || echo "")
# ── Check plugin is installed ─────────────────────────────────────────────────
if [[ ! -f "$INSTALLED_FILE" ]]; then
echo "error: no installed plugins found"
echo " run: claude plugin marketplace add joryeugene/tripod"
echo " claude plugin install tripod"
exit 1
fi
install_path=$(python3 -c "
import json, sys
data = json.load(open('$INSTALLED_FILE'))
entries = data.get('plugins', {}).get('$PLUGIN_KEY', [])
if not entries:
sys.exit(1)
print(entries[0]['installPath'])
" 2>/dev/null)
if [[ -z "$install_path" || ! -d "$install_path" ]]; then
echo "error: tripod plugin not installed"
echo " run: claude plugin install tripod"
exit 1
fi
# ── Step 2: Migrate cache path if version changed ─────────────────────────────
cached_version=$(basename "$install_path")
if [[ "$cached_version" != "$plugin_version" ]]; then
new_path="${install_path%/*}/$plugin_version"
mkdir -p "$new_path"
rsync -a "$install_path/" "$new_path/"
python3 - "$INSTALLED_FILE" "$PLUGIN_KEY" "$cached_version" "$plugin_version" "$git_sha" <<'PYEOF'
import json, os, sys
from datetime import datetime, timezone
f, key, old_ver, new_ver, sha = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]
data = json.load(open(f))
now = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.000Z')
for e in data['plugins'][key]:
e['installPath'] = e['installPath'].replace(old_ver, new_ver)
e['version'] = new_ver
e['gitCommitSha'] = sha
e['lastUpdated'] = now
tmp = f + '.tmp'
with open(tmp, 'w') as fh:
json.dump(data, fh, indent=2)
fh.write('\n')
os.replace(tmp, f)
PYEOF
rm -rf "$install_path"
echo " cache: $cached_version -> $plugin_version"
install_path="$new_path"
else
# Version unchanged: still refresh SHA and lastUpdated so Claude Code's
# update checker sees a consistent state and does not try to migrate.
if [[ -n "$git_sha" ]]; then
python3 - "$INSTALLED_FILE" "$PLUGIN_KEY" "$git_sha" <<'PYEOF'
import json, os, sys
from datetime import datetime, timezone
f, key, sha = sys.argv[1], sys.argv[2], sys.argv[3]
data = json.load(open(f))
now = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.000Z')
for e in data['plugins'][key]:
e['gitCommitSha'] = sha
e['lastUpdated'] = now
tmp = f + '.tmp'
with open(tmp, 'w') as fh:
json.dump(data, fh, indent=2)
fh.write('\n')
os.replace(tmp, f)
PYEOF
fi
fi
# ── Step 3: Sync repo contents to plugin cache ────────────────────────────────
synced=0
for item in skills hooks CLAUDE.md README.md setup verify statusline.sh scripts mcp-presets settings.json.example env.sh.example; do
src="$REPO_DIR/$item"
dst="$install_path/$item"
if [[ -e "$src" ]]; then
if [[ -d "$src" ]]; then
rsync -a --delete --exclude='node_modules' --exclude='bun.lock' "$src/" "$dst/"
else
cp "$src" "$dst"
fi
synced=$((synced + 1))
fi
done
# Remove retired directories that should no longer exist in the cache
for retired in browse; do
if [[ -d "$install_path/$retired" ]]; then
rm -rf "$install_path/$retired"
echo " removed: $retired (retired)"
fi
done
# Clean up orphaned version directories
cache_parent="${install_path%/*}"
for old_dir in "$cache_parent"/*/; do
old_ver=$(basename "$old_dir")
if [[ "$old_ver" != "$plugin_version" && -d "$old_dir" ]]; then
rm -rf "$old_dir"
echo " cleaned: $old_ver (orphaned)"
fi
done
# Also sync plugin metadata to cache root and .claude-plugin/ subdir
# Claude Code reads .claude-plugin/plugin.json for the skill namespace (command prefix)
for meta in .claude-plugin/plugin.json .claude-plugin/marketplace.json; do
src="$REPO_DIR/$meta"
if [[ -f "$src" ]]; then
cp "$src" "$install_path/$(basename "$meta")"
mkdir -p "$install_path/.claude-plugin"
cp "$src" "$install_path/$meta"
fi
done
# ── Step 4: Sync to marketplace snapshot ─────────────────────────────────────
# The marketplace location (~/.claude/plugins/marketplaces/tripod/) is a local
# snapshot Claude Code reads on every startup to determine the "available" version.
# If this snapshot is stale (e.g. version 1.0.0), Claude Code materializes the old
# version directory in the cache on every session start. Keeping it current prevents
# orphaned cache directories from being recreated.
MARKETPLACE_KEY="tripod"
MARKETPLACES_FILE="$HOME/.claude/plugins/known_marketplaces.json"
marketplace_location=$(python3 -c "
import json, sys
data = json.load(open('$MARKETPLACES_FILE'))
entry = data.get('$MARKETPLACE_KEY')
if entry:
print(entry['installLocation'])
" 2>/dev/null)
if [[ -n "$marketplace_location" && -d "$marketplace_location" ]]; then
for item in skills hooks CLAUDE.md README.md setup verify statusline.sh scripts mcp-presets settings.json.example env.sh.example .claude-plugin; do
src="$REPO_DIR/$item"
dst="$marketplace_location/$item"
if [[ -e "$src" ]]; then
if [[ -d "$src" ]]; then
rsync -a --delete --exclude='node_modules' --exclude='bun.lock' "$src/" "$dst/"
else
cp "$src" "$dst"
fi
fi
done
# Remove retired directories from marketplace snapshot
for retired in browse; do
if [[ -d "$marketplace_location/$retired" ]]; then
rm -rf "$marketplace_location/$retired"
fi
done
echo " marketplace snapshot synced ($marketplace_location)"
fi
# ── Summary ───────────────────────────────────────────────────────────────────
skill_count=$(ls "$install_path/skills/" 2>/dev/null | wc -l | tr -d ' ')
hook_count=$(ls "$install_path/hooks/"*.py 2>/dev/null | wc -l | tr -d ' ')
echo "synced $synced items to plugin cache"
echo " version: $plugin_version"
echo " skills: $skill_count"
echo " hooks: $hook_count"
echo " path: $install_path"
echo ""
echo "Start a new session to pick up changes."