Repository navigation
Expand file tree
/
Copy pathsetup-ai.sh
More file actions
executable file
·110 lines (91 loc) · 3.24 KB
/
Copy pathsetup-ai.sh
File metadata and controls
executable file
·110 lines (91 loc) · 3.24 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
#!/bin/bash
# Set up AI tooling config: Mosaic, Claude Code settings.
# The AI CLIs themselves come from Omarchy. Idempotent - safe to re-run.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh"
MOSAIC_BASE_URL="${MOSAIC_BASE_URL:-https://mosaic.heyoodle.com}"
MOSAIC_CLI_INSTALL_URL="https://a.mosaic.heyoodle.com/a/mosaic/cli/install.sh"
mosaic_authenticated() {
timeout 20 mosaic --base-url "$MOSAIC_BASE_URL" list </dev/null >/dev/null 2>&1
}
# Install Mosaic and trigger login when needed. Its skills come from ai-skills.
setup_mosaic() {
hdr "Mosaic"
if command -v mosaic >/dev/null 2>&1; then
ok "mosaic installed: $(mosaic version 2>&1 | head -1)"
else
info "Installing mosaic..."
local installer rc
installer=$(mktemp)
fetch "$MOSAIC_CLI_INSTALL_URL" "$installer" && bash "$installer"
rc=$?
rm -f "$installer"
[ "$rc" -eq 0 ] || return 1
hash -r
if ! command -v mosaic >/dev/null 2>&1; then
warn "mosaic still not on PATH after install"
hint "Ensure ~/.local/bin is on PATH, then re-run tailor."
return 1
fi
ok "mosaic installed: $(mosaic version 2>&1 | head -1)"
fi
if mosaic_authenticated; then
ok "mosaic authenticated"
return 0
fi
# Prompt with a hidden input: mosaic's own paste prompt echoes the token.
local token="${MOSAIC_TOKEN:-}"
if [ -z "$token" ] && is_interactive; then
info "mosaic login required — create a token at:"
hint "$MOSAIC_BASE_URL/my/api_keys (personal) or $MOSAIC_BASE_URL/my/agents (scoped)"
token=$(gum input --password --placeholder "mosaic_pat_..." \
--header "Paste your Mosaic API token (hidden; Esc to skip)") || token=""
fi
if [ -z "$token" ]; then
warn "mosaic login required"
hint "Create a token: $MOSAIC_BASE_URL/my/api_keys (personal) or $MOSAIC_BASE_URL/my/agents (scoped)"
hint "Then re-run: ./tailor.sh ai (or set MOSAIC_TOKEN)"
return 0
fi
# Hand the token over in a private file rather than argv, where ps shows it.
local token_file rc
token_file=$(mktemp)
printf '%s\n' "$token" > "$token_file"
mosaic login --base-url "$MOSAIC_BASE_URL" --token-file "$token_file" </dev/null >/dev/null 2>&1
rc=$?
rm -f "$token_file"
if [ "$rc" -eq 0 ] && mosaic_authenticated; then
ok "mosaic login saved and verified"
else
warn "mosaic rejected that token"
return 1
fi
}
# Setup Claude Code settings
setup_claude_code() {
hdr "Claude Code"
local settings_file="$HOME/.claude/settings.json"
mkdir -p "$HOME/.claude"
if [ ! -f "$settings_file" ]; then
echo '{}' > "$settings_file"
fi
# Disable co-authored-by attribution on commits and PRs
local updated
updated=$(jq '.attribution = { commit: "", pr: "" }' "$settings_file") || {
warn "$settings_file is not valid JSON — left untouched"
return 1
}
echo "$updated" > "$settings_file"
ok "Claude Code settings configured"
}
# Run setup (skills are synced by setup-ai-skills.sh). Each part runs even if
# an earlier one failed; the step fails at the end if any did.
failed=()
setup_mosaic || failed+=("mosaic")
setup_claude_code || failed+=("claude-code")
if [ "${#failed[@]}" -gt 0 ]; then
echo ""
fail "failed: ${failed[*]}"
exit 1
fi