-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·313 lines (291 loc) · 10.6 KB
/
setup.sh
File metadata and controls
executable file
·313 lines (291 loc) · 10.6 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
#!/usr/bin/env bash
# Zero Operators — Environment Bootstrap
# Validates all prerequisites for running ZO.
# Run once per environment: ./setup.sh
set -uo pipefail
# Note: not using -e because arithmetic ((...)) returns 1 when result is 0
AMBER='\033[38;2;240;192;64m'
RED='\033[0;31m'
GREEN='\033[0;32m'
DIM='\033[2m'
RESET='\033[0m'
PASS=0
FAIL=0
WARN=0
FIXABLE_COUNT=0
FIXABLE_ITEMS=""
pass() { echo -e " ${GREEN}✓${RESET} $1"; ((PASS++)); }
fail() { echo -e " ${RED}✗${RESET} $1"; ((FAIL++)); }
warn() { echo -e " ${AMBER}!${RESET} $1"; ((WARN++)); }
fixable() { FIXABLE_ITEMS="$FIXABLE_ITEMS $1"; ((FIXABLE_COUNT++)); }
echo -e "${AMBER}━━━ Zero Operators Setup ━━━${RESET}"
echo ""
# 1. Python version
echo -e "${DIM}Checking Python...${RESET}"
if command -v python3 &>/dev/null; then
PY_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)
if [[ "$PY_MAJOR" -ge 3 && "$PY_MINOR" -ge 11 ]]; then
pass "Python $PY_VERSION"
else
fail "Python $PY_VERSION (need 3.11+)"
fi
else
fail "Python 3 not found"
fi
# 2. uv package manager
echo -e "${DIM}Checking uv...${RESET}"
if command -v uv &>/dev/null; then
UV_VERSION=$(uv --version 2>/dev/null | head -1)
pass "uv ($UV_VERSION)"
else
fail "uv not found — install: curl -LsSf https://astral.sh/uv/install.sh | sh"
fixable "uv"
fi
# 3. Claude Code CLI
echo -e "${DIM}Checking Claude Code CLI...${RESET}"
if command -v claude &>/dev/null; then
pass "Claude Code CLI available"
else
fail "Claude Code CLI not found — install: curl -fsSL https://claude.ai/install.sh | bash"
fixable "claude"
fi
# 4. Agent teams enabled
echo -e "${DIM}Checking agent teams...${RESET}"
SETTINGS_FILE="$HOME/.claude/settings.json"
if [[ -f "$SETTINGS_FILE" ]]; then
if grep -q "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS" "$SETTINGS_FILE" 2>/dev/null; then
pass "Agent teams enabled in global settings"
else
fail "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS not set in $SETTINGS_FILE"
fixable "agent-teams-env"
fi
else
fail "Global settings not found at $SETTINGS_FILE"
fixable "global-settings"
fi
# 5. Project settings.json
echo -e "${DIM}Checking project settings...${RESET}"
if [[ -f ".claude/settings.json" ]]; then
pass "Project .claude/settings.json exists"
else
fail "Project .claude/settings.json missing"
fi
# 6. Agent definition files
echo -e "${DIM}Checking agent definitions...${RESET}"
EXPECTED_AGENTS=(
lead-orchestrator research-scout data-engineer model-builder oracle-qa
code-reviewer test-engineer training-checker xai-agent domain-evaluator
ml-engineer infra-engineer software-architect backend-engineer
frontend-engineer platform-test-engineer platform-code-reviewer
documentation-agent plan-architect data-scout init-architect
)
AGENT_COUNT=0
MISSING_AGENTS=()
for agent in "${EXPECTED_AGENTS[@]}"; do
if [[ -f ".claude/agents/${agent}.md" ]]; then
((AGENT_COUNT++))
else
MISSING_AGENTS+=("$agent")
fi
done
if [[ $AGENT_COUNT -eq 21 ]]; then
pass "All 21 agent definitions present"
else
fail "$AGENT_COUNT/21 agent definitions found"
for missing in "${MISSING_AGENTS[@]}"; do
echo -e " ${RED}missing:${RESET} .claude/agents/${missing}.md"
done
fi
# 7. Git state
echo -e "${DIM}Checking git...${RESET}"
if git rev-parse --is-inside-work-tree &>/dev/null; then
pass "Inside git repository"
if [[ -z "$(git status --porcelain 2>/dev/null)" ]]; then
pass "Working tree clean"
else
warn "Working tree has uncommitted changes"
fi
else
fail "Not a git repository"
fi
# 8. ruff linter
echo -e "${DIM}Checking ruff...${RESET}"
if command -v ruff &>/dev/null; then
pass "ruff available"
else
warn "ruff not found — install: uv tool install ruff"
fi
# 9. Dependencies synced + zo CLI available
echo -e "${DIM}Checking dependencies...${RESET}"
if [[ -f "pyproject.toml" ]]; then
pass "pyproject.toml exists"
if command -v uv &>/dev/null; then
if uv sync --quiet 2>/dev/null; then
pass "Dependencies installed"
else
warn "uv sync failed — run: uv sync"
fi
else
warn "uv not available yet — dependencies not synced"
fi
else
fail "pyproject.toml missing"
fi
echo -e "${DIM}Checking zo CLI...${RESET}"
if command -v zo &>/dev/null && zo --version &>/dev/null 2>&1; then
ZO_VERSION=$(zo --version 2>/dev/null || echo "available")
pass "zo CLI ($ZO_VERSION)"
else
if command -v zo &>/dev/null; then
fail "zo CLI found but broken (stale symlink?) — will reinstall"
else
fail "zo CLI not found on PATH"
fi
fixable "zo-cli"
fi
# 10. Directory structure
echo -e "${DIM}Checking directory structure...${RESET}"
DIRS=(src/zo memory logs targets tests specs plans design)
DIR_OK=0
for dir in "${DIRS[@]}"; do
if [[ -d "$dir" ]]; then
((DIR_OK++))
fi
done
if [[ $DIR_OK -eq ${#DIRS[@]} ]]; then
pass "All ${#DIRS[@]} required directories present"
else
warn "$DIR_OK/${#DIRS[@]} directories present"
fi
# ── Auto-fix ──────────────────────────────────────────────────────────────────
fix_item() {
local item="$1"
case "$item" in
uv)
echo -e " ${AMBER}→${RESET} Installing uv..."
if curl -LsSf https://astral.sh/uv/install.sh | sh 2>/dev/null; then
# Source the env so uv is available for the rest of the script
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if command -v uv &>/dev/null; then
echo -e " ${GREEN}✓${RESET} uv installed ($(uv --version 2>/dev/null | head -1))"
return 0
fi
fi
echo -e " ${RED}✗${RESET} uv install failed — try manually: curl -LsSf https://astral.sh/uv/install.sh | sh"
return 1
;;
claude)
echo -e " ${AMBER}→${RESET} Installing Claude Code CLI..."
if curl -fsSL https://claude.ai/install.sh | bash 2>/dev/null; then
# Refresh PATH for newly installed binary
export PATH="$HOME/.local/bin:$HOME/.claude/local/bin:$PATH"
if command -v claude &>/dev/null; then
echo -e " ${GREEN}✓${RESET} Claude Code CLI installed"
return 0
fi
fi
echo -e " ${RED}✗${RESET} Claude CLI install failed — try manually: curl -fsSL https://claude.ai/install.sh | bash"
return 1
;;
global-settings)
echo -e " ${AMBER}→${RESET} Creating global settings at $SETTINGS_FILE..."
mkdir -p "$HOME/.claude"
cat > "$SETTINGS_FILE" << 'SETTINGS_EOF'
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}
SETTINGS_EOF
echo -e " ${GREEN}✓${RESET} Global settings created with agent teams enabled"
return 0
;;
zo-cli)
echo -e " ${AMBER}→${RESET} Installing zo CLI..."
if ! command -v uv &>/dev/null; then
echo -e " ${RED}✗${RESET} uv required to install zo — fix uv first"
return 1
fi
# Sync deps — uv finds the project root automatically
# (handles worktrees, nested dirs, any cwd)
uv sync --quiet 2>/dev/null
# Ask uv where the venv actually is (don't guess paths)
ZO_VENV_BIN=$(uv run python3 -c "import sys, os; print(os.path.join(sys.prefix, 'bin', 'zo'))" 2>/dev/null)
if [[ -z "$ZO_VENV_BIN" || ! -f "$ZO_VENV_BIN" ]]; then
echo -e " ${RED}✗${RESET} zo binary not found after uv sync — try: uv sync && source .venv/bin/activate"
return 1
fi
# Symlink into ~/.local/bin (already on PATH from uv install)
mkdir -p "$HOME/.local/bin"
ln -sf "$ZO_VENV_BIN" "$HOME/.local/bin/zo"
export PATH="$HOME/.local/bin:$PATH"
if command -v zo &>/dev/null && zo --version &>/dev/null 2>&1; then
echo -e " ${GREEN}✓${RESET} zo CLI installed (symlinked to ~/.local/bin/zo)"
return 0
fi
echo -e " ${RED}✗${RESET} zo symlink created but not working — check PATH includes ~/.local/bin"
return 1
;;
agent-teams-env)
echo -e " ${AMBER}→${RESET} Adding agent teams env to $SETTINGS_FILE..."
# Use python to merge the env key into existing settings
if python3 -c "
import json, sys
with open('$SETTINGS_FILE') as f:
data = json.load(f)
data.setdefault('env', {})['CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS'] = '1'
with open('$SETTINGS_FILE', 'w') as f:
json.dump(data, f, indent=2)
f.write('\n')
" 2>/dev/null; then
echo -e " ${GREEN}✓${RESET} Agent teams env added to global settings"
return 0
else
echo -e " ${RED}✗${RESET} Failed to update settings — add manually"
return 1
fi
;;
esac
}
if [[ $FIXABLE_COUNT -gt 0 && $FAIL -gt 0 ]]; then
echo ""
echo -ne "${AMBER}$FIXABLE_COUNT issue(s) can be auto-fixed. Install now? [Y/n]${RESET} "
read -r REPLY
if [[ -z "$REPLY" || "$REPLY" =~ ^[Yy] ]]; then
echo ""
echo -e "${AMBER}━━━ Auto-fixing $FIXABLE_COUNT issue(s) ━━━${RESET}"
FIXED=0
STILL_BROKEN=0
for item in $FIXABLE_ITEMS; do
if fix_item "$item"; then
((FIXED++))
else
((STILL_BROKEN++))
fi
done
echo ""
if [[ $STILL_BROKEN -eq 0 ]]; then
echo -e "${GREEN}All issues fixed.${RESET} Re-running validation..."
echo ""
exec "$0"
else
echo -e "${AMBER}Fixed $FIXED/$FIXABLE_COUNT.${RESET} $STILL_BROKEN issue(s) need manual attention."
exit 1
fi
fi
fi
# Summary
echo ""
echo -e "${AMBER}━━━ Summary ━━━${RESET}"
echo -e " ${GREEN}Pass:${RESET} $PASS"
[[ $WARN -gt 0 ]] && echo -e " ${AMBER}Warn:${RESET} $WARN"
[[ $FAIL -gt 0 ]] && echo -e " ${RED}Fail:${RESET} $FAIL"
echo ""
if [[ $FAIL -eq 0 ]]; then
echo -e "${GREEN}Environment ready.${RESET} Run ${AMBER}zo build plans/<project>.md${RESET} to start."
else
echo -e "${RED}$FAIL check(s) failed.${RESET} Fix the issues above and re-run ./setup.sh"
exit 1
fi