-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfresh-setup
More file actions
195 lines (172 loc) · 8.7 KB
/
Copy pathfresh-setup
File metadata and controls
195 lines (172 loc) · 8.7 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
#!/usr/bin/env bash
#
# wizard-workbench fresh-setup
#
# For a FRESH start: you've just cloned wizard-workbench and do NOT already
# have the dependency repos (context-mill, wizard, posthog) cloned, nor their
# packages installed. If you already have those, you don't need this — copy
# .env.example to .env and edit the paths by hand (see "Manual setup" in the
# README).
#
# Gets a fresh machine from `git clone` to a runnable `phrocs` stack:
# 1. Checks prerequisites (node, pnpm, git, brew)
# 2. Installs phrocs via brew tap if missing
# 3. Clones context-mill, wizard, and posthog as siblings of this repo
# 4. Writes .env with resolved absolute paths
# 5. Prompts for a PostHog personal API key (optional)
# 6. Runs `pnpm install` in each repo
#
# Flags:
# --force Overwrite an existing .env
# --skip-posthog Don't clone the posthog monorepo (MCP won't work)
# --non-interactive Don't prompt for the API key (leaves placeholder)
#
# To undo: delete the sibling repos and remove .env.
#
# macOS only for now (uses Homebrew). PRs welcome for Linux/Windows.
set -euo pipefail
FORCE=0
SKIP_POSTHOG=0
INTERACTIVE=1
for arg in "$@"; do
case "$arg" in
--force) FORCE=1 ;;
--skip-posthog) SKIP_POSTHOG=1 ;;
--non-interactive) INTERACTIVE=0 ;;
-h|--help)
sed -n '2,26p' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
*)
echo "Unknown flag: $arg" >&2
echo "Run with --help for usage." >&2
exit 2
;;
esac
done
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
PARENT="$(cd "$REPO_ROOT/.." && pwd)"
say() { printf "\033[1;36m==>\033[0m %s\n" "$*"; }
warn() { printf "\033[1;33m!!\033[0m %s\n" "$*" >&2; }
die() { printf "\033[1;31mxx\033[0m %s\n" "$*" >&2; exit 1; }
# ─────────────────────────────────────────────────────────────────────────────
# 1. Preflight
# ─────────────────────────────────────────────────────────────────────────────
say "Checking prerequisites..."
[[ "$(uname -s)" == "Darwin" ]] || die "macOS only for now. See script header."
missing=()
command -v git >/dev/null || missing+=("git (install Xcode command-line tools: xcode-select --install)")
command -v node >/dev/null || missing+=("node (install via https://nodejs.org or 'brew install node')")
command -v pnpm >/dev/null || missing+=("pnpm (install via 'brew install pnpm' or 'npm i -g pnpm')")
command -v brew >/dev/null || missing+=("brew (install via https://brew.sh)")
if (( ${#missing[@]} > 0 )); then
echo "Missing prerequisites:" >&2
printf " - %s\n" "${missing[@]}" >&2
exit 1
fi
# ─────────────────────────────────────────────────────────────────────────────
# 2. phrocs
# ─────────────────────────────────────────────────────────────────────────────
if ! command -v phrocs >/dev/null; then
say "Installing phrocs via Homebrew..."
brew tap posthog/tap
brew install phrocs
else
say "phrocs already installed: $(command -v phrocs)"
fi
# ─────────────────────────────────────────────────────────────────────────────
# 3. Clone sibling repos
# ─────────────────────────────────────────────────────────────────────────────
clone_if_missing() {
local name="$1" url="$2" dest="$PARENT/$1"
if [[ -d "$dest/.git" ]]; then
say "$name already cloned at $dest"
else
say "Cloning $name into $dest..."
git clone "$url" "$dest"
fi
}
clone_if_missing "context-mill" "https://github.com/PostHog/context-mill.git"
clone_if_missing "wizard" "https://github.com/PostHog/wizard.git"
if (( SKIP_POSTHOG == 0 )); then
if [[ ! -d "$PARENT/posthog/.git" ]]; then
warn "About to clone the PostHog monorepo into $PARENT/posthog. This is large (several GB)."
if (( INTERACTIVE == 1 )); then
read -r -p "Continue? [y/N] " ans
[[ "$ans" =~ ^[Yy]$ ]] || die "Aborted. Re-run with --skip-posthog to skip this step."
fi
fi
clone_if_missing "posthog" "https://github.com/PostHog/posthog.git"
else
warn "Skipping posthog clone. MCP processes in phrocs will fail until you clone it."
fi
# ─────────────────────────────────────────────────────────────────────────────
# 4. Write .env
# ─────────────────────────────────────────────────────────────────────────────
ENV_FILE="$REPO_ROOT/.env"
EXAMPLE_FILE="$REPO_ROOT/.env.example"
if [[ -f "$ENV_FILE" && $FORCE -eq 0 ]]; then
say ".env already exists; leaving it alone. Pass --force to overwrite."
else
say "Writing .env from .env.example..."
cp "$EXAMPLE_FILE" "$ENV_FILE"
# macOS sed needs the -i '' form.
sed -i '' \
-e "s|^CONTEXT_MILL_PATH=.*|CONTEXT_MILL_PATH=$PARENT/context-mill|" \
-e "s|^COMMANDMENTS_PATH=.*|COMMANDMENTS_PATH=$PARENT/context-mill/context/commandments.yaml|" \
-e "s|^MCP_PATH=.*|MCP_PATH=$PARENT/posthog/services/mcp|" \
-e "s|^WIZARD_PATH=.*|WIZARD_PATH=$PARENT/wizard|" \
"$ENV_FILE"
fi
# ─────────────────────────────────────────────────────────────────────────────
# 5. API key prompt
# ─────────────────────────────────────────────────────────────────────────────
if (( INTERACTIVE == 1 )); then
current_key="$(grep -E '^POSTHOG_PERSONAL_API_KEY=' "$ENV_FILE" | head -n1 | cut -d= -f2-)"
if [[ "$current_key" == "phx_..." || -z "$current_key" ]]; then
echo
echo "Optional: PostHog personal API key (only needed for wizard-ci and PR evaluator)."
echo "Get one from https://us.posthog.com/settings/user-api-keys — leave blank to skip."
read -r -s -p "POSTHOG_PERSONAL_API_KEY: " api_key
echo
if [[ -n "$api_key" ]]; then
sed -i '' -e "s|^POSTHOG_PERSONAL_API_KEY=.*|POSTHOG_PERSONAL_API_KEY=$api_key|" "$ENV_FILE"
say "API key saved to .env"
else
say "Skipping API key (you can edit .env later)."
fi
else
say "POSTHOG_PERSONAL_API_KEY already set in .env"
fi
fi
# ─────────────────────────────────────────────────────────────────────────────
# 6. Install deps
# ─────────────────────────────────────────────────────────────────────────────
install_in() {
local dir="$1"
if [[ -d "$dir" && -f "$dir/package.json" ]]; then
say "pnpm install in $dir"
(cd "$dir" && pnpm install)
else
warn "Skipping $dir (not a package directory)"
fi
}
install_in "$REPO_ROOT"
install_in "$PARENT/context-mill"
install_in "$PARENT/wizard"
if (( SKIP_POSTHOG == 0 )) && [[ -d "$PARENT/posthog/services/mcp" ]]; then
install_in "$PARENT/posthog/services/mcp"
fi
# ─────────────────────────────────────────────────────────────────────────────
# Done
# ─────────────────────────────────────────────────────────────────────────────
cat <<EOF
$(printf "\033[1;32mAll set.\033[0m")
Next steps:
cd $REPO_ROOT
phrocs
Inside phrocs:
- arrow keys to highlight a process
- 's' starts a manual process (try 'wizard-run')
- 'r' restarts, 'q' quits
EOF