-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-from-upstream.sh
More file actions
executable file
·233 lines (192 loc) · 7.4 KB
/
update-from-upstream.sh
File metadata and controls
executable file
·233 lines (192 loc) · 7.4 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION_FILE="$SCRIPT_DIR/UPSTREAM_VERSION"
# Locate the Claude plugins cache
CLAUDE_DIR="${XDG_CONFIG_HOME:-$HOME/.claude}"
CACHE_DIR="$CLAUDE_DIR/plugins/cache/claude-plugins-official/feature-dev"
if [[ ! -d "$CACHE_DIR" ]]; then
echo "ERROR: Official feature-dev plugin not found in cache."
echo " Expected: $CACHE_DIR"
echo ""
echo "Make sure the feature-dev plugin is installed:"
echo " claude plugin install feature-dev"
exit 1
fi
# Find the most recently modified version in cache
UPSTREAM_DIR=$(ls -dt "$CACHE_DIR"/*/ 2>/dev/null | head -1)
if [[ -z "$UPSTREAM_DIR" ]]; then
echo "ERROR: No cached versions found in $CACHE_DIR"
exit 1
fi
UPSTREAM_HASH=$(basename "$UPSTREAM_DIR")
# Read the last synced version
LAST_SYNCED="(unknown)"
if [[ -f "$VERSION_FILE" ]]; then
LAST_SYNCED=$(grep '^UPSTREAM_HASH=' "$VERSION_FILE" | cut -d= -f2)
fi
echo "=== opsx-feature-dev: upstream comparison ==="
echo ""
echo " Local plugin: $SCRIPT_DIR"
echo " Last synced from: $LAST_SYNCED"
echo " Upstream latest: $UPSTREAM_HASH"
echo ""
if [[ "$LAST_SYNCED" == "$UPSTREAM_HASH" ]]; then
echo " Version: UP TO DATE (same hash)"
else
echo " Version: NEW UPSTREAM VERSION AVAILABLE"
fi
echo ""
# ── Compare agents ──────────────────────────────────────────────
HAS_AGENT_CHANGES=false
HAS_CMD_CHANGES=false
echo "--- Agents ---"
echo ""
for agent in code-explorer code-architect code-reviewer; do
local_file="$SCRIPT_DIR/agents/$agent.md"
upstream_file="$UPSTREAM_DIR/agents/$agent.md"
if [[ ! -f "$upstream_file" ]]; then
echo " SKIP $agent (not in upstream)"
continue
fi
if [[ ! -f "$local_file" ]]; then
echo " NEW $agent exists upstream but not locally"
HAS_AGENT_CHANGES=true
continue
fi
if diff -q "$local_file" "$upstream_file" &>/dev/null; then
echo " OK $agent (identical)"
else
echo " DIFF $agent"
HAS_AGENT_CHANGES=true
fi
done
# Check for new agents upstream that we don't have
for upstream_file in "$UPSTREAM_DIR"/agents/*.md; do
[[ -f "$upstream_file" ]] || continue
agent=$(basename "$upstream_file" .md)
if [[ ! -f "$SCRIPT_DIR/agents/$agent.md" ]]; then
echo " NEW $agent (exists upstream, missing locally)"
HAS_AGENT_CHANGES=true
fi
done
echo ""
# ── Compare command ─────────────────────────────────────────────
echo "--- Command ---"
echo ""
UPSTREAM_CMD="$UPSTREAM_DIR/commands/feature-dev.md"
LOCAL_CMD="$SCRIPT_DIR/commands/feature-dev.md"
if [[ -f "$UPSTREAM_CMD" ]]; then
if diff -q "$LOCAL_CMD" "$UPSTREAM_CMD" &>/dev/null; then
echo " OK feature-dev.md (identical)"
else
echo " DIFF feature-dev.md (expected - yours has OpenSpec integration)"
HAS_CMD_CHANGES=true
fi
else
echo " SKIP upstream command not found"
fi
echo ""
# ── Summary ─────────────────────────────────────────────────────
if [[ "$HAS_AGENT_CHANGES" == false && "$HAS_CMD_CHANGES" == false ]]; then
echo "No changes detected. Your plugin is in sync with upstream."
if [[ "$LAST_SYNCED" != "$UPSTREAM_HASH" ]]; then
echo "Updating UPSTREAM_VERSION to $UPSTREAM_HASH (files identical)."
cat > "$VERSION_FILE" <<VEOF
# Hash of the official feature-dev plugin version that agents were last synced from.
# Updated by update-from-upstream.sh after applying upstream changes.
UPSTREAM_HASH=$UPSTREAM_HASH
VEOF
fi
exit 0
fi
echo "=== Changes detected ==="
echo ""
if [[ "$HAS_AGENT_CHANGES" == true ]]; then
echo "To see agent diffs:"
echo ""
for agent in code-explorer code-architect code-reviewer; do
local_file="$SCRIPT_DIR/agents/$agent.md"
upstream_file="$UPSTREAM_DIR/agents/$agent.md"
if [[ -f "$local_file" && -f "$upstream_file" ]]; then
if ! diff -q "$local_file" "$upstream_file" &>/dev/null; then
echo " diff \"$local_file\" \"$upstream_file\""
fi
fi
done
echo ""
echo "To apply upstream agent changes (review diffs first!):"
echo ""
for agent in code-explorer code-architect code-reviewer; do
upstream_file="$UPSTREAM_DIR/agents/$agent.md"
if [[ -f "$upstream_file" ]]; then
if [[ ! -f "$SCRIPT_DIR/agents/$agent.md" ]] || ! diff -q "$SCRIPT_DIR/agents/$agent.md" "$upstream_file" &>/dev/null; then
echo " cp \"$upstream_file\" \"$SCRIPT_DIR/agents/$agent.md\""
fi
fi
done
echo ""
fi
if [[ "$HAS_CMD_CHANGES" == true ]]; then
echo "To see command diff:"
echo " diff \"$LOCAL_CMD\" \"$UPSTREAM_CMD\""
echo ""
echo "NOTE: The command file will always differ (OpenSpec integration)."
echo " Review for workflow changes you may want to incorporate."
echo ""
fi
# ── Apply flag ──────────────────────────────────────────────────
if [[ "${1:-}" == "--apply" ]]; then
echo "Applying upstream agent changes..."
echo ""
for agent in code-explorer code-architect code-reviewer; do
upstream_file="$UPSTREAM_DIR/agents/$agent.md"
local_file="$SCRIPT_DIR/agents/$agent.md"
if [[ -f "$upstream_file" ]]; then
if [[ ! -f "$local_file" ]] || ! diff -q "$local_file" "$upstream_file" &>/dev/null; then
cp "$upstream_file" "$local_file"
echo " Updated $agent.md"
fi
fi
done
# ── Apply OpenSpec patch to upstream command ───────────────────
PATCH_FILE="$SCRIPT_DIR/openspec-command.patch"
if [[ -f "$PATCH_FILE" && -f "$UPSTREAM_CMD" ]]; then
echo ""
echo "--- Command (patch) ---"
echo ""
# Copy upstream command, then apply OpenSpec patch
cp "$UPSTREAM_CMD" "$LOCAL_CMD"
if git -C "$SCRIPT_DIR" apply "$PATCH_FILE" 2>/dev/null; then
echo " OK Applied OpenSpec patch to upstream command"
else
# Fall back to 3-way merge so conflicts are visible
cp "$UPSTREAM_CMD" "$LOCAL_CMD"
if git -C "$SCRIPT_DIR" apply --3way "$PATCH_FILE" 2>/dev/null; then
echo " MERGE Applied OpenSpec patch with 3-way merge (check for conflicts)"
else
echo " FAIL OpenSpec patch did not apply cleanly."
echo " The upstream command has been copied to: $LOCAL_CMD"
echo " Patch file: $PATCH_FILE"
echo ""
echo " To resolve manually, review the conflict and update the patch:"
echo " 1. Edit commands/feature-dev.md to add OpenSpec changes"
echo " 2. Regenerate the patch:"
echo " diff -u <upstream-cmd> commands/feature-dev.md > openspec-command.patch"
echo " (fix header to use a/ b/ paths)"
fi
fi
fi
# Update version file
cat > "$VERSION_FILE" <<VEOF
# Hash of the official feature-dev plugin version that agents were last synced from.
# Updated by update-from-upstream.sh after applying upstream changes.
UPSTREAM_HASH=$UPSTREAM_HASH
VEOF
echo ""
echo "Done. UPSTREAM_VERSION updated to $UPSTREAM_HASH."
echo "Review changes with 'git diff' and commit when satisfied."
else
echo "Run with --apply to copy upstream agents automatically:"
echo " ./update-from-upstream.sh --apply"
fi