-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·299 lines (264 loc) · 7.55 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·299 lines (264 loc) · 7.55 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage: bash install.sh [options]
Options:
--target <name> Install target: all | universal | codex | claude | openclaw | copilot
all: install canonical skill/toolkit plus native links for Codex, Claude Code, OpenClaw, and GitHub Copilot
universal: install only the canonical Agent Skills layout under ~/.agents
codex|claude|openclaw|copilot: install the canonical layout plus one native link set
--force Overwrite existing installed skill/toolkit
--skip-npm Skip npm install / npm ci in the toolkit
--skip-smoke Skip npm run list smoke test even if STITCH_API_KEY is set
-h, --help Show this help
EOF
}
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
copy_dir() {
local src="$1"
local dest="$2"
mkdir -p "$(dirname "$dest")"
cp -R "$src" "$dest"
}
copy_file_if_exists() {
local src="$1"
local dest="$2"
if [[ -f "$src" ]]; then
mkdir -p "$(dirname "$dest")"
cp "$src" "$dest"
fi
}
copy_toolkit() {
local src="$1"
local dest="$2"
mkdir -p "$dest"
copy_file_if_exists "$src/.env.example" "$dest/.env.example"
copy_file_if_exists "$src/.gitignore" "$dest/.gitignore"
copy_file_if_exists "$src/README.md" "$dest/README.md"
copy_file_if_exists "$src/package.json" "$dest/package.json"
copy_file_if_exists "$src/package-lock.json" "$dest/package-lock.json"
mkdir -p "$dest/scripts"
cp -R "$src/scripts/." "$dest/scripts/"
}
safe_remove() {
local path="$1"
if [[ -L "$path" || -e "$path" ]]; then
rm -rf "$path"
fi
}
create_link() {
local src="$1"
local dest="$2"
mkdir -p "$(dirname "$dest")"
ln -sfn "$src" "$dest"
}
FORCE=0
SKIP_NPM=0
SKIP_SMOKE=0
TARGET="all"
ENV_BACKUP=""
RUNS_BACKUP=""
while [[ $# -gt 0 ]]; do
case "$1" in
--target)
TARGET="${2:-}"
shift
;;
--force)
FORCE=1
;;
--skip-npm)
SKIP_NPM=1
;;
--skip-smoke)
SKIP_SMOKE=1
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 1
;;
esac
shift
done
case "$TARGET" in
all|universal|codex|claude|openclaw|copilot)
;;
*)
echo "Invalid --target value: $TARGET" >&2
usage >&2
exit 1
;;
esac
require_cmd node
require_cmd npm
NODE_MAJOR="$(node -p 'process.versions.node.split(".")[0]')"
if [[ "$NODE_MAJOR" -lt 22 ]]; then
echo "Node.js 22+ is required. Current version: $(node -v)" >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$SCRIPT_DIR"
AGENT_SKILLS_HOME="${AGENT_SKILLS_HOME:-$HOME/.agents}"
STITCH_STARTER_ROOT="${STITCH_STARTER_ROOT:-$AGENT_SKILLS_HOME/stitch-starter}"
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
CLAUDE_HOME="${CLAUDE_HOME:-$HOME/.claude}"
OPENCLAW_HOME="${OPENCLAW_HOME:-$HOME/.openclaw}"
COPILOT_HOME="${COPILOT_HOME:-$HOME/.copilot}"
CANONICAL_SKILL_SRC="$REPO_ROOT/skills/stitchflow"
LEGACY_ALIAS_SKILL_SRC="$REPO_ROOT/skills/stitch-design-local"
TOOLKIT_SRC="$REPO_ROOT/stitch-starter"
CANONICAL_SKILL_DEST="$AGENT_SKILLS_HOME/skills/stitchflow"
LEGACY_ALIAS_SKILL_DEST="$AGENT_SKILLS_HOME/skills/stitch-design-local"
TOOLKIT_DEST="$STITCH_STARTER_ROOT"
CODEX_CANONICAL_LINK="$CODEX_HOME/skills/stitchflow"
CLAUDE_CANONICAL_LINK="$CLAUDE_HOME/skills/stitchflow"
OPENCLAW_CANONICAL_LINK="$OPENCLAW_HOME/skills/stitchflow"
COPILOT_CANONICAL_LINK="$COPILOT_HOME/skills/stitchflow"
CODEX_LEGACY_LINK="$CODEX_HOME/skills/stitch-design-local"
CLAUDE_LEGACY_LINK="$CLAUDE_HOME/skills/stitch-design-local"
OPENCLAW_LEGACY_LINK="$OPENCLAW_HOME/skills/stitch-design-local"
COPILOT_LEGACY_LINK="$COPILOT_HOME/skills/stitch-design-local"
if [[ ! -d "$CANONICAL_SKILL_SRC" || ! -d "$LEGACY_ALIAS_SKILL_SRC" || ! -d "$TOOLKIT_SRC" ]]; then
echo "Repository layout is invalid. Missing skill or toolkit source directory." >&2
exit 1
fi
declare -a LINK_DESTS=()
case "$TARGET" in
all)
LINK_DESTS+=(
"$CODEX_CANONICAL_LINK" "$CODEX_LEGACY_LINK"
"$CLAUDE_CANONICAL_LINK" "$CLAUDE_LEGACY_LINK"
"$OPENCLAW_CANONICAL_LINK" "$OPENCLAW_LEGACY_LINK"
"$COPILOT_CANONICAL_LINK" "$COPILOT_LEGACY_LINK"
)
;;
codex)
LINK_DESTS+=("$CODEX_CANONICAL_LINK" "$CODEX_LEGACY_LINK")
;;
claude)
LINK_DESTS+=("$CLAUDE_CANONICAL_LINK" "$CLAUDE_LEGACY_LINK")
;;
openclaw)
LINK_DESTS+=("$OPENCLAW_CANONICAL_LINK" "$OPENCLAW_LEGACY_LINK")
;;
copilot)
LINK_DESTS+=("$COPILOT_CANONICAL_LINK" "$COPILOT_LEGACY_LINK")
;;
universal)
;;
esac
mkdir -p "$AGENT_SKILLS_HOME/skills"
if [[ -e "$CANONICAL_SKILL_DEST" || -e "$LEGACY_ALIAS_SKILL_DEST" || -e "$TOOLKIT_DEST" ]]; then
if [[ "$FORCE" -ne 1 ]]; then
echo "Destination already exists." >&2
echo "Use --force to overwrite:" >&2
echo " $CANONICAL_SKILL_DEST" >&2
echo " $LEGACY_ALIAS_SKILL_DEST" >&2
echo " $TOOLKIT_DEST" >&2
exit 1
fi
if [[ -f "$TOOLKIT_DEST/.env" ]]; then
ENV_BACKUP="$(mktemp)"
cp "$TOOLKIT_DEST/.env" "$ENV_BACKUP"
fi
if [[ -d "$TOOLKIT_DEST/runs" ]]; then
RUNS_BACKUP="$(mktemp -d)"
cp -R "$TOOLKIT_DEST/runs" "$RUNS_BACKUP/runs"
fi
safe_remove "$CANONICAL_SKILL_DEST"
safe_remove "$LEGACY_ALIAS_SKILL_DEST"
safe_remove "$TOOLKIT_DEST"
fi
for link_dest in "${LINK_DESTS[@]}"; do
if [[ -e "$link_dest" || -L "$link_dest" ]]; then
if [[ "$FORCE" -ne 1 ]]; then
echo "Compatibility link already exists: $link_dest" >&2
echo "Use --force to overwrite existing compatibility links." >&2
exit 1
fi
safe_remove "$link_dest"
fi
done
copy_dir "$CANONICAL_SKILL_SRC" "$CANONICAL_SKILL_DEST"
copy_dir "$LEGACY_ALIAS_SKILL_SRC" "$LEGACY_ALIAS_SKILL_DEST"
copy_toolkit "$TOOLKIT_SRC" "$TOOLKIT_DEST"
if [[ -n "$ENV_BACKUP" ]]; then
cp "$ENV_BACKUP" "$TOOLKIT_DEST/.env"
rm -f "$ENV_BACKUP"
elif [[ ! -f "$TOOLKIT_DEST/.env" ]]; then
cp "$TOOLKIT_DEST/.env.example" "$TOOLKIT_DEST/.env"
fi
if [[ -n "$RUNS_BACKUP" ]]; then
rm -rf "$TOOLKIT_DEST/runs"
cp -R "$RUNS_BACKUP/runs" "$TOOLKIT_DEST/runs"
rm -rf "$RUNS_BACKUP"
fi
for link_dest in "${LINK_DESTS[@]}"; do
if [[ "$link_dest" == *"/stitch-design-local" ]]; then
create_link "$LEGACY_ALIAS_SKILL_DEST" "$link_dest"
else
create_link "$CANONICAL_SKILL_DEST" "$link_dest"
fi
done
if [[ "$SKIP_NPM" -ne 1 ]]; then
(
cd "$TOOLKIT_DEST"
if [[ -f package-lock.json ]]; then
npm ci
else
npm install
fi
)
fi
SMOKE_STATUS="skipped"
if [[ "$SKIP_SMOKE" -ne 1 ]]; then
if grep -Eq '^STITCH_API_KEY=.+$' "$TOOLKIT_DEST/.env"; then
(
cd "$TOOLKIT_DEST"
npm run list
)
SMOKE_STATUS="passed"
else
SMOKE_STATUS="not-run-missing-key"
fi
fi
cat <<EOF
Installed StitchFlow.
Target: $TARGET
Canonical skill: $CANONICAL_SKILL_DEST
Legacy alias skill: $LEGACY_ALIAS_SKILL_DEST
Toolkit: $TOOLKIT_DEST
Node: $(node -v)
NPM: $(npm -v)
Smoke test: $SMOKE_STATUS
Compatibility links:
$(if [[ "${#LINK_DESTS[@]}" -eq 0 ]]; then
echo " (none)"
else
for link_dest in "${LINK_DESTS[@]}"; do
if [[ "$link_dest" == *"/stitch-design-local" ]]; then
echo " $link_dest -> $LEGACY_ALIAS_SKILL_DEST"
else
echo " $link_dest -> $CANONICAL_SKILL_DEST"
fi
done
fi)
Next steps:
1. Add STITCH_API_KEY to $TOOLKIT_DEST/.env if it is empty.
2. Restart your agent client so it picks up the installed skill.
3. Use the canonical skill name: stitchflow
4. Legacy alias still supported: stitch-design-local
5. Use the toolkit from:
cd "$TOOLKIT_DEST"
EOF