-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·540 lines (469 loc) · 19.3 KB
/
install.sh
File metadata and controls
executable file
·540 lines (469 loc) · 19.3 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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/usr/bin/env bash
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CORE_AGENTS="$REPO_ROOT/core/AGENTS.md"
SKILLS_DIR="$REPO_ROOT/skills"
MANAGED_GSTACK_INSTALLER="$REPO_ROOT/scripts/install-managed-gstack.sh"
# Skills that rely on "staying in current conversation" and are incompatible
# with Codex App's architecture (each skill invocation = new task context).
# These skills work via AGENTS.md rule-level recognition instead.
CODEX_EXCLUDED_SKILLS=("btw" "loop")
MANAGED_OFFICIAL_SKILLS=("gstack")
CORE_EXPOSED_GSTACK_SKILLS=(
"gstack"
"gstack-office-hours"
"gstack-plan-ceo-review"
"gstack-plan-design-review"
"gstack-plan-eng-review"
"gstack-design-review"
"gstack-review"
"gstack-investigate"
"gstack-browse"
"gstack-qa"
"gstack-ship"
)
GLOBAL=0
PROJECT=""
ASSUME_YES=0
GSTACK_PROFILE="core"
OFFICIAL_GSTACK_INSTALLED=0
GSTACK_BOOTSTRAP_INSTALLED=0
prepend_path_if_dir() {
local dir="$1"
if [ -d "$dir" ]; then
case ":$PATH:" in
*":$dir:"*) ;;
*) PATH="$dir:$PATH" ;;
esac
fi
}
prepend_common_tool_paths() {
# GUI-launched agents often run non-login shells and miss user tool paths.
prepend_path_if_dir "$HOME/.bun/bin"
prepend_path_if_dir "$HOME/.local/bin"
prepend_path_if_dir "/opt/homebrew/bin"
prepend_path_if_dir "/usr/local/bin"
export PATH
}
prepend_common_tool_paths
while [[ "$#" -gt 0 ]]; do
case $1 in
--global) GLOBAL=1 ;;
--project) PROJECT="$2"; shift ;;
--gstack-profile) GSTACK_PROFILE="$2"; shift ;;
--yes|-y) ASSUME_YES=1 ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
backup_if_exists() {
if [ -f "$1" ]; then
cp "$1" "$1.bak"
echo " Backed up existing: $1 -> $1.bak"
fi
}
path_exists_any() {
for candidate in "$@"; do
if [ -e "$candidate" ]; then
return 0
fi
done
return 1
}
require_skill_file() {
local missing_ref="$1"
shift
local label="$1"
shift
if path_exists_any "$@"; then
return 0
fi
eval "$missing_ref+=(\"\$label\")"
}
verify_managed_gstack_install() {
local missing=()
if [ ! -d "$HOME/.gstack/repos/gstack/.git" ]; then
missing+=("official gstack repo (~/.gstack/repos/gstack)")
fi
require_skill_file missing "Claude runtime (~/.claude/skills/gstack)" \
"$HOME/.claude/skills/gstack/SKILL.md" \
"$HOME/.claude/skills/gstack"
require_skill_file missing "Claude office-hours skill (~/.claude/skills/gstack-office-hours or office-hours)" \
"$HOME/.claude/skills/gstack-office-hours/SKILL.md" \
"$HOME/.claude/skills/office-hours/SKILL.md"
require_skill_file missing "Claude investigate skill (~/.claude/skills/gstack-investigate or investigate)" \
"$HOME/.claude/skills/gstack-investigate/SKILL.md" \
"$HOME/.claude/skills/investigate/SKILL.md"
require_skill_file missing "Claude plan-eng-review skill (~/.claude/skills/gstack-plan-eng-review or plan-eng-review)" \
"$HOME/.claude/skills/gstack-plan-eng-review/SKILL.md" \
"$HOME/.claude/skills/plan-eng-review/SKILL.md"
require_skill_file missing "Claude plan-ceo-review skill (~/.claude/skills/gstack-plan-ceo-review or plan-ceo-review)" \
"$HOME/.claude/skills/gstack-plan-ceo-review/SKILL.md" \
"$HOME/.claude/skills/plan-ceo-review/SKILL.md"
require_skill_file missing "Claude plan-design-review skill (~/.claude/skills/gstack-plan-design-review or plan-design-review)" \
"$HOME/.claude/skills/gstack-plan-design-review/SKILL.md" \
"$HOME/.claude/skills/plan-design-review/SKILL.md"
require_skill_file missing "Claude design-review skill (~/.claude/skills/gstack-design-review or design-review)" \
"$HOME/.claude/skills/gstack-design-review/SKILL.md" \
"$HOME/.claude/skills/design-review/SKILL.md"
require_skill_file missing "Claude browse skill (~/.claude/skills/gstack-browse or browse)" \
"$HOME/.claude/skills/gstack-browse/SKILL.md" \
"$HOME/.claude/skills/browse/SKILL.md"
require_skill_file missing "Claude qa skill (~/.claude/skills/gstack-qa or qa)" \
"$HOME/.claude/skills/gstack-qa/SKILL.md" \
"$HOME/.claude/skills/qa/SKILL.md"
require_skill_file missing "Claude review skill (~/.claude/skills/gstack-review or review)" \
"$HOME/.claude/skills/gstack-review/SKILL.md" \
"$HOME/.claude/skills/review/SKILL.md"
require_skill_file missing "Claude ship skill (~/.claude/skills/gstack-ship or ship)" \
"$HOME/.claude/skills/gstack-ship/SKILL.md" \
"$HOME/.claude/skills/ship/SKILL.md"
require_skill_file missing "Codex gstack runtime (~/.codex/skills/gstack/SKILL.md)" \
"$HOME/.codex/skills/gstack/SKILL.md"
require_skill_file missing "Codex office-hours skill (~/.codex/skills/gstack-office-hours/SKILL.md)" \
"$HOME/.codex/skills/gstack-office-hours/SKILL.md"
require_skill_file missing "Codex investigate skill (~/.codex/skills/gstack-investigate/SKILL.md)" \
"$HOME/.codex/skills/gstack-investigate/SKILL.md"
require_skill_file missing "Codex plan-eng-review skill (~/.codex/skills/gstack-plan-eng-review/SKILL.md)" \
"$HOME/.codex/skills/gstack-plan-eng-review/SKILL.md"
require_skill_file missing "Codex plan-ceo-review skill (~/.codex/skills/gstack-plan-ceo-review/SKILL.md)" \
"$HOME/.codex/skills/gstack-plan-ceo-review/SKILL.md"
require_skill_file missing "Codex plan-design-review skill (~/.codex/skills/gstack-plan-design-review/SKILL.md)" \
"$HOME/.codex/skills/gstack-plan-design-review/SKILL.md"
require_skill_file missing "Codex design-review skill (~/.codex/skills/gstack-design-review/SKILL.md)" \
"$HOME/.codex/skills/gstack-design-review/SKILL.md"
require_skill_file missing "Codex browse skill (~/.codex/skills/gstack-browse/SKILL.md)" \
"$HOME/.codex/skills/gstack-browse/SKILL.md"
require_skill_file missing "Codex qa skill (~/.codex/skills/gstack-qa/SKILL.md)" \
"$HOME/.codex/skills/gstack-qa/SKILL.md"
require_skill_file missing "Codex review skill (~/.codex/skills/gstack-review/SKILL.md)" \
"$HOME/.codex/skills/gstack-review/SKILL.md"
require_skill_file missing "Codex ship skill (~/.codex/skills/gstack-ship/SKILL.md)" \
"$HOME/.codex/skills/gstack-ship/SKILL.md"
if [ "${#missing[@]}" -gt 0 ]; then
echo "Official gstack install is incomplete. Missing:" >&2
for item in "${missing[@]}"; do
echo " - $item" >&2
done
echo "Lotus global rules live in AGENTS/CLAUDE files, but slash skills must exist in each host's global skills directory." >&2
return 1
fi
}
confirm_global_rule_overwrite() {
local existing=()
for candidate in "$@"; do
if [ -f "$candidate" ]; then
existing+=("$candidate")
fi
done
if [ "${#existing[@]}" -eq 0 ]; then
return 0
fi
if [ "$ASSUME_YES" -eq 1 ] || [ "${LOTUS_ASSUME_YES:-0}" = "1" ]; then
echo " Overwrite confirmation skipped (--yes / LOTUS_ASSUME_YES=1)."
return 0
fi
if [ ! -t 0 ]; then
echo "Existing global rule/config files would be overwritten, but no interactive confirmation is available." >&2
echo "Re-run with --yes (or LOTUS_ASSUME_YES=1) if you want Lotus to overwrite them automatically." >&2
return 1
fi
echo "Existing global rule/config files detected. Lotus will back them up to .bak and then overwrite them:"
for file_path in "${existing[@]}"; do
echo " - $file_path"
done
echo
read -r -p "Continue and overwrite these global files? [y/N] " response
case "$response" in
y|Y|yes|YES)
return 0
;;
*)
echo "Cancelled. No global rules were overwritten."
return 1
;;
esac
}
copy_lotus_skills() {
local target_dir="$1"
shift
mkdir -p "$target_dir"
for skill_file in "$SKILLS_DIR"/*.md; do
local skill_name
skill_name="$(basename "$skill_file" .md)"
local should_skip=false
for excluded in "$@"; do
if [ "$skill_name" = "$excluded" ]; then
should_skip=true
break
fi
done
if [ "$should_skip" = false ]; then
cp "$skill_file" "$target_dir/"
fi
done
}
claude_gstack_skill_name() {
local skill_name="$1"
if [ "$skill_name" = "gstack" ]; then
echo "gstack"
else
echo "${skill_name#gstack-}"
fi
}
write_gstack_bootstrap_skill() {
local skill_file="$1"
local skill_name="$2"
local display_name="$3"
cat > "$skill_file" <<BOOTSTRAP_EOF
---
name: $skill_name
description: |
Bootstrap entry for official gstack $display_name. Lotus installed this fallback because the full official gstack runtime was not available during global setup.
allowed-tools:
- Read
- AskUserQuestion
---
# Official gstack bootstrap
This is a real top-level skill entry, installed so gstack slash commands do not disappear when the full official runtime cannot be installed.
The full official gstack runtime is not installed yet. To enable this skill's full workflow:
1. Install Git, bash, and bun.
2. Open a fresh terminal.
3. Re-run:
\`\`\`bash
install.sh --global
\`\`\`
If you are running from outside the Lotus repo, use the full path to \`install.sh\`.
BOOTSTRAP_EOF
}
is_gstack_bootstrap_skill_file() {
local skill_file="$1"
[ -f "$skill_file" ] && grep -q "Bootstrap entry for official gstack" "$skill_file"
}
write_gstack_bootstrap_skill_if_needed() {
local skill_file="$1"
local skill_name="$2"
local display_name="$3"
local only_missing="${4:-0}"
if [ -f "$skill_file" ]; then
if ! is_gstack_bootstrap_skill_file "$skill_file"; then
return 1
fi
if [ "$only_missing" -eq 1 ]; then
return 1
fi
fi
write_gstack_bootstrap_skill "$skill_file" "$skill_name" "$display_name"
return 0
}
install_gstack_bootstrap_skills() {
local only_missing="${1:-0}"
local codex_skill
local claude_skill
local display_name
local codex_dir
local claude_dir
local written=0
local preserved=0
mkdir -p "$HOME/.codex/skills" "$HOME/.claude/skills"
for codex_skill in "${CORE_EXPOSED_GSTACK_SKILLS[@]}"; do
display_name="${codex_skill#gstack-}"
if [ "$codex_skill" = "gstack" ]; then
display_name="runtime"
fi
codex_dir="$HOME/.codex/skills/$codex_skill"
mkdir -p "$codex_dir"
if write_gstack_bootstrap_skill_if_needed "$codex_dir/SKILL.md" "$codex_skill" "$display_name" "$only_missing"; then
written=$((written + 1))
else
preserved=$((preserved + 1))
fi
claude_skill="$(claude_gstack_skill_name "$codex_skill")"
claude_dir="$HOME/.claude/skills/$claude_skill"
mkdir -p "$claude_dir"
if write_gstack_bootstrap_skill_if_needed "$claude_dir/SKILL.md" "$claude_skill" "$display_name" "$only_missing"; then
written=$((written + 1))
else
preserved=$((preserved + 1))
fi
done
echo " Installed bootstrap entries for the 11 official gstack top-level skills ($written written, $preserved preserved)"
}
# Convert a Lotus skill .md file into a Codex-compatible SKILL.md directory.
# Codex expects: ~/.codex/skills/<name>/SKILL.md with YAML frontmatter containing
# name, description, and allowed-tools fields.
convert_to_codex_skill() {
local source_file="$1"
local target_dir="$2"
local content
content=$(cat "$source_file")
local skill_name=""
local description=""
if echo "$content" | head -1 | grep -q "^---"; then
local frontmatter
frontmatter=$(awk '
NR == 1 && $0 == "---" {
in_frontmatter = 1
next
}
in_frontmatter == 1 && $0 == "---" {
exit
}
in_frontmatter == 1 {
print
}
' "$source_file")
skill_name=$(echo "$frontmatter" | grep '^name:' | sed 's/^name:[[:space:]]*//' || true)
description=$(echo "$frontmatter" | grep '^description:' | sed 's/^description:[[:space:]]*//' || true)
fi
if [ -z "$skill_name" ]; then
skill_name=$(basename "$source_file" .md)
fi
if [ -z "$description" ]; then
description="Lotus skill: $skill_name"
fi
local allowed_tools
case "$skill_name" in
auto-build) allowed_tools="Bash\n - Read" ;;
btw) allowed_tools="Read\n - AskUserQuestion" ;;
feynman) allowed_tools="Read\n - AskUserQuestion" ;;
polanyi-tacit) allowed_tools="Read\n - AskUserQuestion" ;;
powerup) allowed_tools="Read\n - AskUserQuestion" ;;
insights) allowed_tools="Read\n - Bash\n - Grep\n - Glob" ;;
image-2) allowed_tools="Read\n - Write\n - Edit\n - Grep\n - Glob\n - Bash\n - AskUserQuestion" ;;
loop) allowed_tools="Bash\n - Read\n - AskUserQuestion" ;;
agent-training-loop) allowed_tools="Read\n - Write\n - Edit\n - Grep\n - Glob\n - Bash\n - AskUserQuestion" ;;
baseline-packager) allowed_tools="Read\n - Write\n - Edit\n - Grep\n - Glob\n - Bash\n - AskUserQuestion" ;;
conversion-copywriter) allowed_tools="Read\n - AskUserQuestion" ;;
subagent) allowed_tools="Bash\n - Read\n - Write\n - Edit\n - Grep\n - Glob\n - AskUserQuestion" ;;
web-to-design-md) allowed_tools="Read\n - Write\n - Edit\n - Grep\n - Glob\n - AskUserQuestion\n - WebSearch" ;;
taste-skill) allowed_tools="Read\n - Write\n - Edit\n - Grep\n - Glob\n - Bash\n - AskUserQuestion" ;;
gstack) allowed_tools="Bash\n - Read\n - Write\n - Edit\n - Grep\n - Glob\n - AskUserQuestion" ;;
*) allowed_tools="Read\n - AskUserQuestion" ;;
esac
local body
body=$(awk '
NR == 1 && $0 == "---" {
in_frontmatter = 1
next
}
in_frontmatter == 1 && $0 == "---" {
in_frontmatter = 0
next
}
in_frontmatter == 1 {
next
}
{
print
}
' "$source_file")
local skill_dir="$target_dir/$skill_name"
mkdir -p "$skill_dir"
cat > "$skill_dir/SKILL.md" <<CODEX_EOF
---
name: $skill_name
description: |
$description
allowed-tools:
- $(echo -e "$allowed_tools")
---
$body
CODEX_EOF
echo " Converted skill: $skill_name"
}
if [ "$GLOBAL" -eq 1 ]; then
echo -e "\033[0;36mInstalling Global Rules & Skills...\033[0m"
CLAUDE_RULE_FILE="$HOME/.claude/CLAUDE.md"
CODEX_RULE_FILE="$HOME/.codex/AGENTS.md"
if ! confirm_global_rule_overwrite \
"$CLAUDE_RULE_FILE" \
"$CODEX_RULE_FILE"; then
exit 1
fi
mkdir -p ~/.claude/skills
backup_if_exists "$CLAUDE_RULE_FILE"
cp "$CORE_AGENTS" "$CLAUDE_RULE_FILE"
copy_lotus_skills ~/.claude/skills "${MANAGED_OFFICIAL_SKILLS[@]}"
echo " Claude Code configured"
mkdir -p ~/.codex/skills
backup_if_exists "$CODEX_RULE_FILE"
cp "$CORE_AGENTS" "$CODEX_RULE_FILE"
for excluded in "${CODEX_EXCLUDED_SKILLS[@]}"; do
if [ -d "$HOME/.codex/skills/$excluded" ]; then
rm -rf "$HOME/.codex/skills/$excluded"
echo " Removed incompatible skill: $excluded"
fi
done
for skill_file in "$SKILLS_DIR"/*.md; do
skill_name=$(basename "$skill_file" .md)
is_excluded=false
for excluded in "${CODEX_EXCLUDED_SKILLS[@]}" "${MANAGED_OFFICIAL_SKILLS[@]}"; do
if [ "$skill_name" = "$excluded" ]; then
is_excluded=true
break
fi
done
if [ "$is_excluded" = true ]; then
echo " Skipped (managed elsewhere or in-context only): $skill_name"
else
convert_to_codex_skill "$skill_file" ~/.codex/skills
fi
done
echo " Codex CLI configured (rules + Lotus-only compatible skills)"
echo " Installing official gstack upstream..."
if LOTUS_GSTACK_PROFILE="$GSTACK_PROFILE" bash "$MANAGED_GSTACK_INSTALLER"; then
verify_managed_gstack_install
OFFICIAL_GSTACK_INSTALLED=1
echo " Official gstack configured for Claude/Codex"
else
echo "Official gstack installation failed. Installing bootstrap slash entries instead." >&2
install_gstack_bootstrap_skills 1
GSTACK_BOOTSTRAP_INSTALLED=1
fi
echo ""
echo -e "\033[0;32mGlobal installation completed successfully!\033[0m"
echo -e "\033[0;33mIf any existing configs were overwritten, .bak backups have been created.\033[0m"
echo ""
echo -e "\033[0;36mCodex note:\033[0m"
echo " - Global rules were installed to ~/.codex/AGENTS.md and are auto-loaded in local repos."
echo " - --global does not create AGENTS.md inside each project folder."
echo " - Run ./install.sh --project nextjs|vite|html inside a project when you want local AGENTS.md and .agents/rules/ files."
if [ "$OFFICIAL_GSTACK_INSTALLED" -eq 1 ]; then
echo " - Official gstack is managed at ~/.gstack/repos/gstack and kept auto-updatable."
elif [ "$GSTACK_BOOTSTRAP_INSTALLED" -eq 1 ]; then
echo " - The 11 official gstack top-level skill entries were installed as bootstrap skills."
echo " - Install Git, bash, and bun, then re-run ./install.sh --global to install the full official gstack runtime."
fi
echo " - Official gstack top-level exposure profile: $GSTACK_PROFILE"
echo " - Hidden official gstack skills stay in ~/.gstack/repos/gstack/.agents/skills and can still be routed by AGENTS.md."
echo " - Slash skills live in the managed global skills folders ~/.claude/skills and ~/.codex/skills."
fi
if [ -n "$PROJECT" ]; then
echo -e "\033[0;36mInstalling Project Template: $PROJECT...\033[0m"
TEMPLATE_DIR="$REPO_ROOT/templates/$PROJECT"
if [ ! -d "$TEMPLATE_DIR" ]; then
echo -e "\033[0;31mTemplate '$PROJECT' not found.\033[0m"
exit 1
fi
cp -R "$TEMPLATE_DIR"/* .
cp -R "$TEMPLATE_DIR"/.[!.]* . 2>/dev/null || true
CONVENTIONS_FILE="$REPO_ROOT/core/CONVENTIONS.md"
if [ -f "$CONVENTIONS_FILE" ]; then
cp "$CONVENTIONS_FILE" .
fi
echo -e "\033[0;32mProject template '$PROJECT' applied to current directory.\033[0m"
echo -e "\033[0;33mRemember to adjust the design system and tech stack files in .agents/rules/.\033[0m"
fi
if [ "$GLOBAL" -eq 0 ] && [ -z "$PROJECT" ]; then
echo -e "\033[0;36mLotus Installer\033[0m"
echo "--------------------"
echo "Usage:"
echo " ./install.sh --global (Install global rules to the managed Claude/Codex folders)"
echo " ./install.sh --global --gstack-profile core (Default curated official gstack top-level set)"
echo " ./install.sh --global --gstack-profile full (Expose the full official gstack top-level set)"
echo " ./install.sh --global --yes (Overwrite existing global configs without prompting)"
echo " ./install.sh --project <name> (Apply template to current directory)"
echo ""
echo "Available gstack profiles: core, design, review, deploy, full"
echo "Available templates: nextjs, vite, html"
fi