Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·118 lines (103 loc) · 4.74 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·118 lines (103 loc) · 4.74 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
#!/usr/bin/env bash
# bootstrap.sh — install swarmspace: just binary, recipes, scripts, and ws wrapper.
#
# Idempotent. Safe to run multiple times. No sudo required (even on Linux).
#
# Usage:
# ./bootstrap.sh # one-shot install from a local clone
#
# Fresh machine setup:
# git clone https://github.com/AndurilCode/swarmspace
# cd swarmspace
# ./bootstrap.sh
set -euo pipefail
# ── Locations ────────────────────────────────────────────────────────────────
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLUGIN_TARGET="$HOME/.config/swarmspace"
SCRIPT_TARGET="$PLUGIN_TARGET/scripts"
AGENT_TARGET="$PLUGIN_TARGET/agents"
JUSTFILE_TARGET="$HOME/.config/just/justfile"
WS_BIN="$HOME/.local/bin/ws"
# ── Install just (no sudo anywhere) ──────────────────────────────────────────
install_just() {
command -v just >/dev/null 2>&1 && return 0
echo "→ installing just..." >&2
# Prefer Homebrew if available — idiomatic on macOS, user-mode install, no sudo
if command -v brew >/dev/null 2>&1; then
if brew install just >&2; then
return 0
fi
echo " brew install failed; falling back to official installer" >&2
fi
# Universal fallback: prebuilt binary to ~/.local/bin, no sudo, no compile
mkdir -p "$HOME/.local/bin"
if curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh \
| bash -s -- --to "$HOME/.local/bin" >&2; then
: # installed
else
echo "⚠ just install failed — see https://just.systems/man/en/prerequisites.html" >&2
return 1
fi
# Warn if ~/.local/bin isn't on PATH (the bootstrap can't touch shell rc)
case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) echo "⚠ \$HOME/.local/bin is not on PATH — add 'export PATH=\"\$HOME/.local/bin:\$PATH\"' to your shell rc" >&2 ;;
esac
}
# ── Deploy scripts + agents + justfile + ws wrapper ──────────────────────────
deploy() {
mkdir -p "$SCRIPT_TARGET" "$AGENT_TARGET" \
"$(dirname "$JUSTFILE_TARGET")" "$(dirname "$WS_BIN")"
# Scripts: every ws-*.sh in the repo's scripts/ dir
cp "$REPO_DIR"/scripts/ws-*.sh "$SCRIPT_TARGET/"
chmod +x "$SCRIPT_TARGET"/ws-*.sh
# Agents: every *.md (the canonical filename used by Claude Code).
# We also copy the *.agent.md symlinks so Copilot CLI discovers agents under
# its own convention. Both names resolve to the same underlying content.
if compgen -G "$REPO_DIR/agents/*.md" >/dev/null; then
# Use -L to resolve symlinks (so deployed copies are real files, not
# broken symlinks pointing into $REPO_DIR)
cp -L "$REPO_DIR"/agents/*.md "$AGENT_TARGET/"
# Re-create the .agent.md → .md symlinks inside the deployed dir for
# Copilot compatibility, since `cp -L` flattened them above.
for f in "$AGENT_TARGET"/*.md; do
[ -f "$f" ] || continue
base=$(basename "$f" .md)
# Skip if this is ALREADY an .agent.md file (from an older layout)
[[ "$base" == *.agent ]] && continue
ln -sf "$base.md" "$AGENT_TARGET/$base.agent.md"
done
fi
# Clean up pre-2.1 flat layout (scripts used to live directly under
# $PLUGIN_TARGET, not in a scripts/ subdir). Harmless no-op on fresh installs.
find "$PLUGIN_TARGET" -maxdepth 1 -name 'ws-*.sh' -delete 2>/dev/null || true
# Justfile: copy as-is to just's global location. The recipes read
# SWARMSPACE_SCRIPTS via env_var_or_default; the ws wrapper exports it.
{
echo "# Deployed by swarmspace bootstrap — source: $REPO_DIR"
cat "$REPO_DIR/justfile"
} > "$JUSTFILE_TARGET"
# ws wrapper: exports the scripts path (so the justfile's env_var_or_default
# picks it up at parse time), then invokes just with the global justfile.
cat > "$WS_BIN" <<EOF
#!/usr/bin/env bash
export SWARMSPACE_SCRIPTS="\${SWARMSPACE_SCRIPTS:-$SCRIPT_TARGET}"
exec just --global-justfile "\$@"
EOF
chmod +x "$WS_BIN"
}
# ── Main ─────────────────────────────────────────────────────────────────────
install_just || exit 1
deploy
echo ""
echo "✓ swarmspace installed"
echo " Justfile: $JUSTFILE_TARGET"
echo " Scripts: $SCRIPT_TARGET/"
echo " Agents: $AGENT_TARGET/"
echo " Wrapper: $WS_BIN"
echo ""
echo "Usage:"
echo " ws # list recipes (if \$HOME/.local/bin is on PATH)"
echo " just -g # list recipes (native just invocation)"
echo " ws swarm <dir> 3 \"<task>\""
echo " ws investigate <dir> 3 --goal \"...\" --scope \"...\""