coulomb-social/scripts/run-design-extract.sh
tegwick 6fe263444a Extract authenticated coulomb.social design language via designlang
Session probe lands on /vw_pages (Research). Use main designlang extract
with --cookie-file — pack ignores auth. 39 artifacts under
docs/design-extract; tolerate designlang late summary crash when cores exist.
2026-08-09 01:31:00 +02:00

104 lines
3.7 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run designlang against coulomb.social using a captured Playwright storageState.
# Does not print secrets. Requires: ./scripts/capture-auth-state.sh first.
#
# NOTE: designlang's `pack` subcommand does NOT pass --cookie-file into the
# crawler (it calls extractDesignLanguage(url) with no auth options). Use the
# main extract command, which does apply cookies from storageState.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
AUTH_DIR="${COULOMB_SOCIAL_AUTH_DIR:-$HOME/.config/coulomb-social/auth}"
STATE_PATH="${COULOMB_SOCIAL_STORAGE_STATE:-$AUTH_DIR/storage-state.json}"
OUT_DIR="${COULOMB_SOCIAL_EXTRACT_OUT:-$ROOT/docs/design-extract}"
URL="${COULOMB_SOCIAL_URL:-https://coulomb.social}"
WAIT_MS="${COULOMB_SOCIAL_EXTRACT_WAIT:-5000}"
if [[ ! -f "$STATE_PATH" ]]; then
echo "ERROR: No auth session at $STATE_PATH" >&2
echo "Capture one first (interactive login as your user):" >&2
echo " $ROOT/scripts/capture-auth-state.sh" >&2
echo "Docs: $ROOT/docs/design-extract-auth.md" >&2
exit 1
fi
mode="$(stat -c '%a' "$STATE_PATH" 2>/dev/null || stat -f '%Lp' "$STATE_PATH" 2>/dev/null || echo '?')"
if [[ "$mode" != "600" && "$mode" != "0600" ]]; then
echo "warning: $STATE_PATH mode is $mode (prefer 600)" >&2
fi
echo "==> probing session (no secrets printed)…"
PROBE_URL="$(
cd "$ROOT/scripts" && \
COULOMB_SOCIAL_STORAGE_STATE="$STATE_PATH" \
COULOMB_SOCIAL_URL="$URL" \
node ./probe-auth-session.mjs
)" || PROBE_URL=""
if [[ -n "$PROBE_URL" ]]; then
echo " session lands on: $PROBE_URL"
if [[ "$PROBE_URL" == "https://coulomb.social/" || "$PROBE_URL" == "https://coulomb.social" ]]; then
echo "warning: session still on site root — may be guest; re-run capture-auth-state.sh if extract looks empty" >&2
fi
fi
mkdir -p "$OUT_DIR"
echo "==> designlang extract (main command — cookies applied)"
echo " url: $URL"
echo " auth: $STATE_PATH (session file present; not printed)"
echo " out: $OUT_DIR"
echo " wait: ${WAIT_MS}ms"
echo " extra: $*"
# Main command supports --cookie-file. Prefer a rich capture of the live app UI.
set +e
npx --yes designlang "$URL" \
--cookie-file "$STATE_PATH" \
-o "$OUT_DIR" \
-n coulomb-social \
--wait "$WAIT_MS" \
--depth "${COULOMB_SOCIAL_EXTRACT_DEPTH:-2}" \
--interactions \
--verbose \
"$@"
dl_ec=$?
set -e
# designlang can crash late while printing summary (Buffer.byteLength on undefined
# content for optional emitters) after already writing the useful artifacts.
if [[ $dl_ec -ne 0 ]]; then
if [[ -f "$OUT_DIR/coulomb-social-design-language.md" && -f "$OUT_DIR/coulomb-social-design-tokens.json" ]]; then
echo "warning: designlang exited $dl_ec after writing core artifacts (known late summary bug); treating as success" >&2
else
echo "ERROR: designlang failed (exit $dl_ec) and core artifacts are missing" >&2
exit "$dl_ec"
fi
fi
# Drop root-level pack leftovers from earlier mistaken `pack` runs (no cookies).
if [[ -d "$ROOT/coulomb-social-design-system" ]]; then
echo "==> removing unauthenticated pack leftover: coulomb-social-design-system/"
rm -rf "$ROOT/coulomb-social-design-system"
fi
# Provenance (no secrets)
cat > "$OUT_DIR/PROVENANCE.md" <<EOF
# Design extract provenance
| Field | Value |
|-------|--------|
| Source | $URL |
| Tool | designlang (main extract, not pack) |
| Captured | $(date -Iseconds) |
| Auth | Playwright storageState via --cookie-file |
| Session probe | ${PROBE_URL:-unknown} |
| designlang exit | $dl_ec |
## Note
Use \`./scripts/run-design-extract.sh\` — do **not** use \`designlang pack\` for
authenticated crawls; pack ignores cookies.
EOF
echo "==> done. Inspect: $OUT_DIR"
ls -la "$OUT_DIR" | head -50