-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsetup
More file actions
executable file
·455 lines (398 loc) · 14.5 KB
/
setup
File metadata and controls
executable file
·455 lines (398 loc) · 14.5 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/usr/bin/env bash
# nanostack setup — register skills with Claude Code / Codex / Kiro
# No build step required. No runtime dependencies.
#
# Install:
# git clone https://github.com/garagon/nanostack.git ~/.claude/skills/nanostack
# cd ~/.claude/skills/nanostack && ./setup
#
# Per-repo:
# git clone https://github.com/garagon/nanostack.git .claude/skills/nanostack
# cd .claude/skills/nanostack && ./setup
#
# Codex:
# git clone https://github.com/garagon/nanostack.git ~/nanostack
# cd ~/nanostack && ./setup --host codex
set -e
NANOSTACK_DIR="$(cd "$(dirname "$0")" && pwd)"
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd -P)"
SKILLS_DIR="$(dirname "$NANOSTACK_DIR")"
SKILLS=(think nano review qa security ship guard conductor compound)
# Map skill name to directory (when they differ)
skill_dir() {
case "$1" in
nano) echo "plan" ;;
*) echo "$1" ;;
esac
}
# sed -i portability (BSD vs GNU)
if sed --version >/dev/null 2>&1; then
sed_inplace() { sed -i "$@"; }
else
sed_inplace() { sed -i '' "$@"; }
fi
# ─── Parse flags ──────────────────────────────────────────────
HOST="claude"
LOCAL_INSTALL=0
RENAMES=""
while [ $# -gt 0 ]; do
case "$1" in
--host) [ -z "${2:-}" ] && echo "Missing value for --host" >&2 && exit 1; HOST="$2"; shift 2 ;;
--host=*) HOST="${1#--host=}"; shift ;;
--local) LOCAL_INSTALL=1; shift ;;
--rename) [ -z "${2:-}" ] && echo "Missing value for --rename" >&2 && exit 1; RENAMES="$2"; shift 2 ;;
--rename=*) RENAMES="${1#--rename=}"; shift ;;
--list) LIST_SKILLS=1; shift ;;
--help)
cat <<'HELP'
Usage: ./setup [OPTIONS]
Options:
--host <agent> Target: claude (default), codex, cursor, opencode, gemini, auto
--local Install to .claude/skills/ in current working directory
--rename <map> Rename skills to avoid collisions (comma-separated old=new pairs)
--rename reset Restore all skills to their original names
--list Show installed skills and their current names
--help Show this help
Install methods:
# Global (recommended)
git clone https://github.com/garagon/nanostack.git ~/.claude/skills/nanostack
cd ~/.claude/skills/nanostack && ./setup
# Per-repo
./setup --local
# Multi-agent
./setup --host auto
# Rename skills that collide with other tools
./setup --rename "review=nano-review,security=nano-security"
# See current skill names
./setup --list
# Restore original names
./setup --rename reset
HELP
exit 0
;;
*) shift ;;
esac
done
# Handle --list (show skills and exit)
if [ "${LIST_SKILLS:-0}" -eq 1 ]; then
echo "Nanostack Skills"
echo "================"
# Load saved renames
if [ -f "$HOME/.nanostack/setup.json" ]; then
saved=$(jq -r '.renames // {} | to_entries[] | "\(.key)=\(.value)"' "$HOME/.nanostack/setup.json" 2>/dev/null | tr '\n' ' ')
fi
for skill in "${SKILLS[@]}"; do
renamed=""
for pair in $saved; do
old="${pair%%=*}"
new="${pair#*=}"
if [ "$old" = "$skill" ]; then
renamed="$new"
break
fi
done
if [ -n "$renamed" ]; then
echo " /$renamed (original: /$skill)"
else
echo " /$skill"
fi
done
echo ""
echo "To rename: ./setup --rename \"review=nano-review\""
echo "To reset: ./setup --rename reset"
exit 0
fi
# Handle --rename reset
if [ "$RENAMES" = "reset" ]; then
RENAMES=""
if [ -f "$HOME/.nanostack/setup.json" ]; then
jq '.renames = {}' "$HOME/.nanostack/setup.json" > "$HOME/.nanostack/setup.json.tmp" && \
mv "$HOME/.nanostack/setup.json.tmp" "$HOME/.nanostack/setup.json"
fi
echo "Renames cleared. Running setup with original names..."
echo ""
fi
case "$HOST" in
claude|codex|cursor|opencode|gemini|auto) ;;
*) echo "Unknown --host: $HOST (expected claude, codex, cursor, opencode, gemini, or auto)" >&2; exit 1 ;;
esac
# --local override
if [ "$LOCAL_INSTALL" -eq 1 ]; then
SKILLS_DIR="$(pwd)/.claude/skills"
mkdir -p "$SKILLS_DIR"
NANOSTACK_LOCAL="$SKILLS_DIR/nanostack"
if [ ! -e "$NANOSTACK_LOCAL" ]; then
ln -snf "$SOURCE_DIR" "$NANOSTACK_LOCAL"
echo "Linked $NANOSTACK_LOCAL → $SOURCE_DIR"
fi
HOST="claude"
fi
# ─── Rename map ──────────────────────────────────────────────
# Parse --rename "review=ns-review,security=ns-sec" into a lookup.
# Renames persist in ~/.nanostack/setup.json so upgrade.sh reapplies them.
# Uses a flat string "old=new old2=new2" for bash 3 compatibility (macOS).
RENAME_PAIRS=""
if [ -z "$RENAMES" ]; then
# Load saved renames from previous setup
if [ -f "$HOME/.nanostack/setup.json" ]; then
saved_renames=$(jq -r '.renames // {} | to_entries[] | "\(.key)=\(.value)"' "$HOME/.nanostack/setup.json" 2>/dev/null | tr '\n' ',')
RENAMES="${saved_renames%,}"
fi
fi
if [ -n "$RENAMES" ]; then
RENAME_PAIRS=$(echo "$RENAMES" | tr ',' ' ')
fi
# Get the public name for a skill (after renames)
skill_public_name() {
local skill="$1"
for pair in $RENAME_PAIRS; do
local old="${pair%%=*}"
local new="${pair#*=}"
if [ "$old" = "$skill" ]; then
echo "$new"
return
fi
done
echo "$skill"
}
# Install a renamed skill: copy SKILL.md with updated name in frontmatter
install_renamed_skill() {
local skill="$1"
local public_name="$2"
local target_dir="$3"
local dir
dir=$(skill_dir "$skill")
mkdir -p "$target_dir/$public_name"
# Copy SKILL.md with updated name field
sed "s/^name: .*/name: $public_name/" "$SOURCE_DIR/$dir/SKILL.md" > "$target_dir/$public_name/SKILL.md"
# Symlink everything else (references, templates, bin, etc.)
for item in "$SOURCE_DIR/$dir"/*; do
local basename
basename=$(basename "$item")
[ "$basename" = "SKILL.md" ] && continue
ln -snf "$item" "$target_dir/$public_name/$basename" 2>/dev/null || true
done
}
# ─── Auto-detect agents ──────────────────────────────────────
INSTALL_CLAUDE=0
INSTALL_CODEX=0
INSTALL_CURSOR=0
INSTALL_OPENCODE=0
INSTALL_GEMINI=0
if [ "$HOST" = "auto" ]; then
command -v claude >/dev/null 2>&1 && INSTALL_CLAUDE=1
command -v codex >/dev/null 2>&1 && INSTALL_CODEX=1
command -v cursor >/dev/null 2>&1 && INSTALL_CURSOR=1
command -v opencode >/dev/null 2>&1 && INSTALL_OPENCODE=1
command -v gemini >/dev/null 2>&1 && INSTALL_GEMINI=1
# Default to claude if nothing detected
TOTAL=$((INSTALL_CLAUDE + INSTALL_CODEX + INSTALL_CURSOR + INSTALL_OPENCODE + INSTALL_GEMINI))
[ "$TOTAL" -eq 0 ] && INSTALL_CLAUDE=1
elif [ "$HOST" = "claude" ]; then
INSTALL_CLAUDE=1
elif [ "$HOST" = "codex" ]; then
INSTALL_CODEX=1
elif [ "$HOST" = "cursor" ]; then
INSTALL_CURSOR=1
elif [ "$HOST" = "opencode" ]; then
INSTALL_OPENCODE=1
elif [ "$HOST" = "gemini" ]; then
INSTALL_GEMINI=1
fi
# ─── Claude Code ──────────────────────────────────────────────
# Creates symlinks from ~/.claude/skills/<skill> → nanostack/<skill>
# so Claude Code discovers each skill as a top-level slash command.
install_claude() {
local skills_dir="$1"
local linked=()
local renamed=()
# Check we're inside a skills directory
local basename
basename="$(basename "$skills_dir")"
if [ "$basename" != "skills" ]; then
echo " (skipped skill symlinks — not inside a skills/ directory)"
echo " Recommended: git clone into ~/.claude/skills/nanostack"
return
fi
for skill in "${SKILLS[@]}"; do
local public_name
public_name=$(skill_public_name "$skill")
local dir
dir=$(skill_dir "$skill")
# Clean up: remove old symlink with the original name if we're renaming
if [ "$public_name" != "$skill" ]; then
[ -L "$skills_dir/$skill" ] && rm -f "$skills_dir/$skill"
fi
local target="$skills_dir/$public_name"
# Always remove stale symlink/dir at target to recreate cleanly
[ -L "$target" ] && rm -f "$target"
[ -d "$target" ] && [ ! -L "$target" ] && rm -rf "$target"
if [ "$public_name" != "$skill" ]; then
# Renamed: copy SKILL.md with new name, symlink the rest
install_renamed_skill "$skill" "$public_name" "$skills_dir"
renamed+=("/$skill > /$public_name")
else
# Normal: symlink the directory
ln -snf "nanostack/$dir" "$target"
linked+=("$skill")
fi
done
if [ ${#linked[@]} -gt 0 ]; then
echo " Linked skills: ${linked[*]}"
fi
if [ ${#renamed[@]} -gt 0 ]; then
echo " Renamed skills: ${renamed[*]}"
fi
}
# ─── OpenAI Codex ─────────────────────────────────────────────
# Creates nanostack-<skill> directories with symlinks in ~/.codex/skills/
install_codex() {
local codex_skills="${HOME}/.codex/skills"
mkdir -p "$codex_skills"
# Create runtime root with symlinks to source
local codex_root="$codex_skills/nanostack"
mkdir -p "$codex_root"
ln -snf "$SOURCE_DIR/SKILL.md" "$codex_root/SKILL.md"
ln -snf "$SOURCE_DIR/AGENTS.md" "$codex_root/AGENTS.md"
local linked=()
for skill in "${SKILLS[@]}"; do
local target="$codex_skills/nanostack-${skill}"
if [ -L "$target" ] || [ ! -e "$target" ]; then
ln -snf "$SOURCE_DIR/$skill" "$target"
linked+=("nanostack-${skill}")
fi
done
if [ ${#linked[@]} -gt 0 ]; then
echo " Linked skills: ${linked[*]}"
fi
}
# ─── Cursor ───────────────────────────────────────────────────
# Creates .cursor/rules/ with skill references
install_cursor() {
local cursor_rules=".cursor/rules"
mkdir -p "$cursor_rules"
# Create a rule that loads nanostack skills
cat > "$cursor_rules/nanostack.md" << CURSORRULE
---
description: "Nanostack engineering workflow skills"
alwaysApply: true
---
You have access to nanostack skills. Read SKILL.md files in ~/.claude/skills/nanostack/ for instructions.
Available: /think, /nano, /review, /qa, /security, /ship, /guard, /conductor
Workflow: /think → /nano → build → /review → /qa → /security → /ship
CURSORRULE
echo " Created $cursor_rules/nanostack.md"
}
# ─── OpenCode ─────────────────────────────────────────────────
# Symlinks into ~/.agents/skills/ (OpenCode scans this natively)
install_opencode() {
local agents_skills="${HOME}/.agents/skills"
mkdir -p "$agents_skills"
local agents_root="$agents_skills/nanostack"
if [ -L "$agents_root" ] || [ ! -e "$agents_root" ]; then
ln -snf "$SOURCE_DIR" "$agents_root"
echo " Linked $agents_root → $SOURCE_DIR"
fi
}
# ─── Gemini CLI ───────────────────────────────────────────────
# Installs as Gemini extension
install_gemini() {
echo " Gemini CLI: run 'gemini extensions install $SOURCE_DIR' to install"
echo " Or for development: 'gemini extensions link $SOURCE_DIR'"
}
# ─── Config ──────────────────────────────────────────────────
# Persist installation metadata to ~/.nanostack/setup.json
write_setup_config() {
local config_dir="$HOME/.nanostack"
mkdir -p "$config_dir"
local agents="[]"
[ "$INSTALL_CLAUDE" -eq 1 ] && agents=$(echo "$agents" | jq '. + ["claude"]')
[ "$INSTALL_CODEX" -eq 1 ] && agents=$(echo "$agents" | jq '. + ["codex"]')
[ "$INSTALL_CURSOR" -eq 1 ] && agents=$(echo "$agents" | jq '. + ["cursor"]')
[ "$INSTALL_OPENCODE" -eq 1 ] && agents=$(echo "$agents" | jq '. + ["opencode"]')
[ "$INSTALL_GEMINI" -eq 1 ] && agents=$(echo "$agents" | jq '. + ["gemini"]')
# Build renames JSON object
local renames_json="{}"
for pair in $RENAME_PAIRS; do
local old="${pair%%=*}"
local new="${pair#*=}"
renames_json=$(echo "$renames_json" | jq --arg k "$old" --arg v "$new" '. + {($k): $v}')
done
jq -n \
--arg src "$SOURCE_DIR" \
--arg ver "$(git -C "$SOURCE_DIR" describe --tags 2>/dev/null || git -C "$SOURCE_DIR" rev-parse --short HEAD 2>/dev/null || echo 'unknown')" \
--argjson agents "$agents" \
--argjson local "$LOCAL_INSTALL" \
--argjson renames "$renames_json" \
--arg date "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
'{
schema_version: "1",
source: $src,
version: $ver,
agents: $agents,
local_install: ($local == 1),
renames: $renames,
installed_at: $date
}' > "$config_dir/setup.json"
}
# ─── Execute ──────────────────────────────────────────────────
echo "Nanostack Setup"
echo "================"
echo ""
if [ "$INSTALL_CLAUDE" -eq 1 ]; then
install_claude "$SKILLS_DIR"
if [ "$LOCAL_INSTALL" -eq 1 ]; then
echo "nanostack ready (claude, project-local)."
else
echo "nanostack ready (claude)."
fi
echo " skills: $SKILLS_DIR"
fi
if [ "$INSTALL_CODEX" -eq 1 ]; then
install_codex
echo "nanostack ready (codex)."
echo " skills: ${HOME}/.codex/skills"
fi
if [ "$INSTALL_CURSOR" -eq 1 ]; then
install_cursor
echo "nanostack ready (cursor)."
fi
if [ "$INSTALL_OPENCODE" -eq 1 ]; then
install_opencode
echo "nanostack ready (opencode)."
echo " skills: ${HOME}/.agents/skills/nanostack"
fi
if [ "$INSTALL_GEMINI" -eq 1 ]; then
install_gemini
echo "nanostack ready (gemini)."
fi
# Save installation config
write_setup_config
echo ""
echo " config: ~/.nanostack/setup.json"
echo ""
echo "Available skills:"
for skill in "${SKILLS[@]}"; do
pname=$(skill_public_name "$skill")
if [ "$pname" != "$skill" ]; then
echo " /$pname (renamed from /$skill)"
else
echo " /$skill"
fi
done
echo ""
# Build workflow line with renames applied
w_think=$(skill_public_name "think")
w_nano=$(skill_public_name "nano")
w_review=$(skill_public_name "review")
w_qa=$(skill_public_name "qa")
w_security=$(skill_public_name "security")
w_ship=$(skill_public_name "ship")
w_guard=$(skill_public_name "guard")
echo "Workflow: /$w_think → /$w_nano → build → /$w_review → /$w_qa → /$w_security → /$w_ship"
echo "Safety: /$w_guard (activate on-demand)"
echo ""
echo "Per-project setup (run once in each project):"
echo " ~/.claude/skills/nanostack/bin/init-project.sh"
echo ""
echo "Update: ~/.claude/skills/nanostack/bin/upgrade.sh"