-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·449 lines (388 loc) · 15.7 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·449 lines (388 loc) · 15.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
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
#!/bin/bash
set -euo pipefail
# ═══════════════════════════════════════════════════════════
# EVC — Setup Script
# Reads config.env, renders _templates/ → .claude/, sets permissions.
# Safe to run multiple times (idempotent).
# Works on macOS (BSD) and Linux (GNU).
# ═══════════════════════════════════════════════════════════
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e " ${GREEN}[OK]${NC} $1"; }
warn() { echo -e " ${YELLOW}[!]${NC} $1"; }
error() { echo -e " ${RED}[X]${NC} $1"; }
header() { echo -e "\n${BLUE}${BOLD}$1${NC}"; }
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"
# Cross-platform sed in-place flag
if [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
SED_INPLACE=(-i '')
else
SED_INPLACE=(-i)
fi
# Escape value for use as sed replacement (handles &, |, \)
sed_escape() {
printf '%s' "$1" | sed -e 's/[\\&|]/\\&/g'
}
echo ""
echo -e "${BOLD}EVC${NC} — Marketing Agent System for Claude Code"
echo -e "────────────────────────────────────────────────────"
# ── Step 1: Prerequisites ──
header "Checking prerequisites..."
command -v claude &>/dev/null && info "Claude Code installed" || warn "Claude Code not found (install from https://claude.ai/code)"
[[ "${BASH_VERSION%%.*}" -ge 4 ]] 2>/dev/null && info "Bash 4+ ($BASH_VERSION)" || warn "Bash version may be old ($BASH_VERSION)"
if python3 -c 'pass' &>/dev/null; then
info "Python 3 available"
elif command -v python3 &>/dev/null; then
warn "python3 found but not runnable — on macOS run: xcode-select --install (some hooks degrade without it)"
else
warn "Python 3 not found — some hooks may not work"
fi
command -v sed &>/dev/null && info "sed available" || { error "sed not found"; exit 1; }
command -v git &>/dev/null && info "git available" || warn "git not found — upgrade command will not work"
# ── Step 2: Config ──
header "Loading configuration..."
if [[ ! -f "config.env" ]]; then
warn "No config.env found."
echo ""
echo " Choose an industry starter:"
echo " 1) Web3 / Crypto / DeFi"
echo " 2) B2B SaaS"
echo " 3) E-commerce / D2C"
echo " 4) Generic (any industry)"
echo ""
read -p " Select (1-4): " choice
case "$choice" in
1) cp starters/web3.env config.env && info "Copied Web3 starter" ;;
2) cp starters/saas.env config.env && info "Copied SaaS starter" ;;
3) cp starters/ecommerce.env config.env && info "Copied E-commerce starter" ;;
*) cp starters/generic.env config.env && info "Copied Generic starter" ;;
esac
echo ""
echo -e " ${YELLOW}Edit config.env with your company details, then re-run ./setup.sh${NC}"
echo " At minimum, fill in: COMPANY_NAME, WEBSITE_URL, SOCIAL_HANDLE_X, ANCHOR_STATEMENT, BRAND_PRIMARY_COLOR"
echo ""
if [[ -n "${EDITOR:-}" ]]; then
"$EDITOR" config.env || true
elif command -v code &>/dev/null; then
code config.env || true
fi
exit 0
fi
# Parse config.env line-by-line (handles $10, $100 literally — no shell expansion)
# Only accepts plain KEY="value" assignments. Skips comments and blank lines.
parse_config() {
local line key val
while IFS= read -r line || [ -n "$line" ]; do
# Strip carriage returns, leading/trailing whitespace
line="${line%$'\r'}"
line="${line#"${line%%[![:space:]]*}"}"
# Skip blank lines and comments
[ -z "$line" ] && continue
[[ "$line" == \#* ]] && continue
[[ "$line" == "#!"* ]] && continue
# Extract KEY=VALUE (KEY must be uppercase/digit/underscore)
if [[ "$line" =~ ^([A-Z_][A-Z0-9_]*)=(.*)$ ]]; then
key="${BASH_REMATCH[1]}"
val="${BASH_REMATCH[2]}"
# Strip surrounding double quotes if present
if [[ "$val" == \"*\" ]]; then
val="${val:1:${#val}-2}"
elif [[ "$val" == \'*\' ]]; then
val="${val:1:${#val}-2}"
fi
# Strip trailing inline comment (# after whitespace)
val="${val%% #*}"
val="${val% }"
# Export with literal value (no expansion)
printf -v "$key" '%s' "$val"
export "$key"
fi
done < config.env
}
parse_config
info "config.env loaded"
# Validate required vars
MISSING=0
for var in COMPANY_NAME WEBSITE_URL SOCIAL_HANDLE_X ANCHOR_STATEMENT BRAND_PRIMARY_COLOR; do
if [[ -z "${!var:-}" ]]; then
error "Missing required variable: $var"
MISSING=1
fi
done
[[ $MISSING -eq 1 ]] && { echo ""; error "Fix config.env and re-run ./setup.sh"; exit 1; }
info "Required variables validated"
# Defaults for optional vars
COMPANY_SLUG="${COMPANY_SLUG:-$(echo "$COMPANY_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')}"
SOCIAL_HANDLE_LINKEDIN="${SOCIAL_HANDLE_LINKEDIN:-}"
BRAND_SECONDARY_COLOR="${BRAND_SECONDARY_COLOR:-#111827}"
PROOF_POINT_1="${PROOF_POINT_1:-}"
PROOF_POINT_2="${PROOF_POINT_2:-}"
DEFUNCT_REFERENCE="${DEFUNCT_REFERENCE:-}"
PRODUCT_CORE_NAME="${PRODUCT_CORE_NAME:-Product}"
CMS_COLLECTION_ID="${CMS_COLLECTION_ID:-}"
CMS_BLOG_LISTING_ID="${CMS_BLOG_LISTING_ID:-}"
CMS_BLOG_DETAIL_ID="${CMS_BLOG_DETAIL_ID:-}"
CMS_FIELD_TITLE="${CMS_FIELD_TITLE:-}"
CMS_FIELD_CONTENT="${CMS_FIELD_CONTENT:-}"
CMS_FIELD_COVER="${CMS_FIELD_COVER:-}"
CMS_FIELD_DATE="${CMS_FIELD_DATE:-}"
CMS_FIELD_AUTHOR="${CMS_FIELD_AUTHOR:-}"
CMS_FIELD_EXCERPT="${CMS_FIELD_EXCERPT:-}"
CMS_FIELD_CATEGORY="${CMS_FIELD_CATEGORY:-}"
LINEAR_TEAM_PREFIX="${LINEAR_TEAM_PREFIX:-MAR}"
COMPLIANCE_JURISDICTIONS="${COMPLIANCE_JURISDICTIONS:-US,EU,UK}"
# Fixed directory paths (repo-relative — same for all users)
BRAND_DIR="brand"
CANON_DIR="brand"
CONFIG_DIR="."
CONTENT_ENGINE_DIR="content-engine"
CONTENT_OUTPUT_DIR="content-engine/output"
PLANS_DIR="."
PROJECT_ROOT="."
SECRETS_DIR=".secrets"
SESSION_DIR=".claude/session-data"
TEMPLATES_DIR="_templates"
# Bare X handle (no @)
SOCIAL_HANDLE_X_BARE="${SOCIAL_HANDLE_X#@}"
# Color defaults for templates
COLOR_PRIMARY="${BRAND_PRIMARY_COLOR}"
COLOR_BG_DARK="${BRAND_SECONDARY_COLOR}"
COLOR_BG_DARK_ALT="#0a1a12"
# Pass-through defaults
COMPANY_HANDLE="${SOCIAL_HANDLE_X}"
PARTNER_LIST="${PROOF_POINT_1}, ${PROOF_POINT_2}"
PRIMARY_TEAM="${LINEAR_TEAM_PREFIX}"
INDUSTRY="${INDUSTRY:-generic}"
DISCORD_CHANNEL_ID="${DISCORD_CHANNEL_IDS:-}"
# ── Step 3: Create directory skeleton ──
# Git doesn't track empty directories, so fresh clones are missing the
# working dirs that commands and setup.sh expect. Create them all here.
header "Setting up workspace..."
mkdir -p \
.secrets \
.claude/session-data \
.claude/metrics \
brand/logos \
brand/templates \
brand/canon-history/snapshots \
content-engine/calendar \
content-engine/exports \
content-engine/memory \
content-engine/output/reports \
staging/blog \
staging/social \
staging/assets \
staging/dashboards \
staging/references
chmod 700 .secrets
info "Workspace directories created"
info ".secrets/ permissions set (chmod 700)"
# ── Step 4: Render templates (idempotent) ──
header "Rendering templates..."
# Clean slate: remove stale rendered files
rm -rf .claude/commands .claude/hooks .claude/contexts
# Copy template directories
cp -R _templates/commands .claude/commands
cp -R _templates/hooks .claude/hooks
cp -R _templates/contexts .claude/contexts
# Copy individual template files
# Framework files: always refreshed (rendered artifacts)
cp _templates/SOUL.md SOUL.md
cp _templates/CLAUDE.md CLAUDE.md
cp _templates/skill-triggers.md .claude/skill-triggers.md
# User data files: NEVER overwrite an existing one — /setup-canon and manual
# edits live here. Fresh installs get the template; re-runs preserve user work.
if [ ! -f "brand/canon-rules.json" ]; then
cp _templates/canon-rules.json brand/canon-rules.json
info "brand/canon-rules.json created from template"
else
info "brand/canon-rules.json exists — preserved (delete it to re-seed from template)"
fi
if [ ! -f "content-engine/config.md" ]; then
cp _templates/content-config.md content-engine/config.md
info "content-engine/config.md created from template"
else
info "content-engine/config.md exists — preserved"
fi
# Canon history directory (seeded later after canon cleanup)
mkdir -p brand/canon-history/snapshots
if [ ! -f "brand/canon-history/CHANGELOG.md" ] && [ -f "_templates/canon-history/CHANGELOG.md" ]; then
cp _templates/canon-history/CHANGELOG.md brand/canon-history/CHANGELOG.md
fi
info "Templates copied to .claude/"
# Render staging dashboards + shared CSS
mkdir -p staging/dashboards staging/blog staging/social staging/assets staging/references
if [ -d "_templates/dashboards" ]; then
cp _templates/dashboards/*.html staging/dashboards/ 2>/dev/null || true
fi
if [ -f "_templates/staging/staging-base.css" ]; then
cp _templates/staging/staging-base.css staging/dashboards/staging-base.css
fi
# Link or copy index.html to staging root
if [ -f "_templates/dashboards/index.html" ]; then
cp _templates/dashboards/index.html staging/index.html
fi
info "Staging dashboards rendered"
# Build sed arguments as an array (preserves whitespace in values)
# Only variables actually referenced as {{TOKEN}} in _templates/ are listed here.
# Others (COMPANY_SLUG, SOCIAL_HANDLE_LINKEDIN, BRAND_SECONDARY_COLOR, LINEAR_TEAM_PREFIX,
# COMPLIANCE_JURISDICTIONS) are still parsed from config.env and available at runtime to
# commands via env — they just don't need template substitution.
VARS=(
COMPANY_NAME WEBSITE_URL SOCIAL_HANDLE_X SOCIAL_HANDLE_X_BARE
BRAND_PRIMARY_COLOR
ANCHOR_STATEMENT PROOF_POINT_1 PROOF_POINT_2 DEFUNCT_REFERENCE
PRODUCT_CORE_NAME CMS_COLLECTION_ID CMS_BLOG_LISTING_ID CMS_BLOG_DETAIL_ID
CMS_FIELD_TITLE CMS_FIELD_CONTENT CMS_FIELD_COVER CMS_FIELD_DATE
CMS_FIELD_AUTHOR CMS_FIELD_EXCERPT CMS_FIELD_CATEGORY
BRAND_DIR CANON_DIR CONFIG_DIR CONTENT_ENGINE_DIR CONTENT_OUTPUT_DIR
PLANS_DIR PROJECT_ROOT SECRETS_DIR SESSION_DIR
COLOR_PRIMARY COLOR_BG_DARK COLOR_BG_DARK_ALT
COMPANY_HANDLE PARTNER_LIST PRIMARY_TEAM INDUSTRY DISCORD_CHANNEL_ID
)
SED_ARGS=()
for var in "${VARS[@]}"; do
val="${!var:-}"
esc=$(sed_escape "$val")
SED_ARGS+=(-e "s|{{${var}}}|${esc}|g")
done
# Render all rendered files (properly grouped find)
FILE_COUNT=0
while IFS= read -r file; do
sed "${SED_INPLACE[@]}" "${SED_ARGS[@]}" "$file" 2>/dev/null || true
FILE_COUNT=$((FILE_COUNT + 1))
done < <(find .claude brand/canon-rules.json content-engine/config.md SOUL.md CLAUDE.md staging -type f \( -name "*.md" -o -name "*.json" -o -name "*.sh" -o -name "*.html" -o -name "*.css" \) 2>/dev/null)
info "Variables substituted in $FILE_COUNT files"
# Replace any remaining {{TOKENS}} in staging dashboards with "—"
# (Dashboard-specific tokens are populated later by /project:dashboards commands)
if [ -d "staging/dashboards" ]; then
find staging/dashboards -type f -name "*.html" 2>/dev/null | while IFS= read -r file; do
sed "${SED_INPLACE[@]}" -E 's/\{\{[A-Z_0-9]+\}\}/—/g' "$file" 2>/dev/null || true
done
fi
# Same cleanup for staging/index.html (one level up, also a dashboard)
if [ -f "staging/index.html" ]; then
sed "${SED_INPLACE[@]}" -E 's/\{\{[A-Z_0-9]+\}\}/—/g' staging/index.html 2>/dev/null || true
fi
# Post-process canon-rules.json: strip empty-string entries
if command -v python3 &>/dev/null && [ -f "brand/canon-rules.json" ]; then
python3 - << 'PYEOF' 2>/dev/null || true
import json
from pathlib import Path
path = Path("brand/canon-rules.json")
try:
with open(path) as f:
data = json.load(f)
except Exception:
raise SystemExit(0)
data["banned_phrases"] = [
p for p in data.get("banned_phrases", [])
if p.get("phrase", "").strip()
]
data["defunct_partners"] = [
p for p in data.get("defunct_partners", [])
if isinstance(p, str) and p.strip()
]
data["live_partners"] = [
p for p in data.get("live_partners", [])
if isinstance(p, str) and p.strip()
]
with open(path, "w") as f:
json.dump(data, f, indent=2)
PYEOF
info "canon-rules.json cleaned"
fi
# Seed canon baseline snapshot + cache (after cleanup, so diffs are accurate)
if [ ! "$(ls -A brand/canon-history/snapshots 2>/dev/null | grep -v .gitkeep)" ]; then
BASELINE_STAMP=$(date +"%Y%m%d-%H%M")
cp brand/canon-rules.json "brand/canon-history/snapshots/canon-${BASELINE_STAMP}-baseline.json"
fi
cp brand/canon-rules.json .claude/.canon-cache.json
info "Canon history seeded"
# ── Step 5: Set permissions ──
header "Setting permissions..."
chmod 600 config.env
chmod 755 .claude/hooks/*.sh 2>/dev/null || true
chmod 644 .claude/commands/*.md 2>/dev/null || true
chmod 644 .claude/contexts/*.md 2>/dev/null || true
chmod 755 scripts/*.sh 2>/dev/null || true
chmod 700 .secrets
info "File permissions set"
# ── Step 6: Write settings.json ──
header "Wiring hooks..."
cat > .claude/settings.json << SETTINGS
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/block-no-verify.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/commit-quality.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/canon-guardrail.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/suggest-compact.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/check-reference.sh"}
]
}
],
"PreCompact": [
{
"matcher": "",
"hooks": [
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/pre-compact.sh"}
]
}
],
"SessionStart": [
{
"matcher": "",
"hooks": [
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/session-start.sh"}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/session-end.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/desktop-notify.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/cost-tracker.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/action-audit.sh"},
{"type": "command", "command": "${PROJECT_DIR}/.claude/hooks/canon-changelog.sh"}
]
}
]
}
}
SETTINGS
chmod 600 .claude/settings.json
info "settings.json written (10 hooks wired)"
# ── Step 7: Validation ──
if [[ -x "scripts/validate.sh" ]]; then
header "Validating setup..."
bash scripts/validate.sh || warn "Some validation checks need attention (see above)"
fi
# ── Summary ──
echo ""
echo -e "════════════════════════════════════════════════════"
echo -e "${GREEN}${BOLD}EVC — Setup Complete${NC}"
echo -e "════════════════════════════════════════════════════"
echo -e " Company: ${BOLD}${COMPANY_NAME}${NC}"
echo -e " Commands: $(ls .claude/commands/*.md 2>/dev/null | wc -l | tr -d ' ') installed"
echo -e " Hooks: $(ls .claude/hooks/*.sh 2>/dev/null | wc -l | tr -d ' ') available (12 wired)"
echo -e " Modes: $(ls .claude/contexts/*.md 2>/dev/null | wc -l | tr -d ' ') available"
echo -e " Brand: brand/canon-rules.json"
echo ""
echo -e " ${BOLD}Next steps:${NC}"
echo -e " 1. Open Claude Code in this directory"
echo -e " 2. Run ${GREEN}/project:start${NC} for guided onboarding"
echo -e " 3. Run ${GREEN}/project:setup-canon${NC} to build your brand rules"
echo -e " 4. Run ${GREEN}/project:monday${NC} to start your first week"
echo -e " 5. Run ${GREEN}/project:help${NC} to see all commands"
echo ""