#!/usr/bin/env bash # Auto-generate marketplace src/data/*.ts from real public kit content. # Run from repo root; targets ~/Projects/keisei-marketplace/src/data/. # # Usage: # ./tools/marketplace-sync/sync.sh set -uo pipefail # Note: -e disabled — grep+head+sed pipelines may legitimately return # non-zero when a Cargo.toml has no `description` field; we handle that # case explicitly via the `[ -z "$DESC" ]` fallback inside each loop. KIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)" MARKETPLACE_DIR="${MARKETPLACE_DIR:-$HOME/Projects/keisei-marketplace}" DATA_DIR="$MARKETPLACE_DIR/src/data" if [ ! -d "$DATA_DIR" ]; then echo "error: marketplace data dir not found: $DATA_DIR" >&2 exit 1 fi echo "Kit: $KIT_DIR" echo "Marketplace: $MARKETPLACE_DIR" echo "" # --- primitives.ts --- echo "▶ Generating primitives.ts from Cargo workspace..." WORKSPACE_TOML="$KIT_DIR/_primitives/_rust/Cargo.toml" PRIMS=() while IFS= read -r line; do PRIMS+=("$line"); done < <(awk '/^members = \[/,/^]/' "$WORKSPACE_TOML" | grep -oE '"[^"]+"' | tr -d '"' | sort -u) TOTAL=${#PRIMS[@]} echo " Found $TOTAL workspace members" cat > "$DATA_DIR/primitives.ts" <
/dev/null | head -1 | sed 's/description = "//; s/"$//; s/\\/\\\\/g; s/"/\\"/g') [ -z "$DESC" ] && DESC="Rust primitive in the KeiSeiKit substrate." cat >> "$DATA_DIR/primitives.ts" <> "$DATA_DIR/primitives.ts" <<'FOOTER' ]; export const PRIMITIVES_BY_SLUG = Object.fromEntries( PRIMITIVES.map((p) => [p.slug, p]) ); FOOTER echo " Wrote $(grep -c '^ {' "$DATA_DIR/primitives.ts") primitive entries" # --- skills.ts --- echo "" echo "▶ Generating skills.ts from skills/ dir..." SKILLS=() while IFS= read -r line; do SKILLS+=("$line"); done < <(ls "$KIT_DIR/skills/" 2>/dev/null | sort -u) SCOUNT=${#SKILLS[@]} echo " Found $SCOUNT skill directories" cat > "$DATA_DIR/skills.ts" <
> "$DATA_DIR/skills.ts" <> "$DATA_DIR/skills.ts" <<'FOOTER' ]; export const SKILLS_BY_SLUG = Object.fromEntries( SKILLS.map((s) => [s.slug, s]) ); FOOTER echo " Wrote $(grep -c '^ {' "$DATA_DIR/skills.ts") skill entries" # --- hooks.ts --- echo "" echo "▶ Generating hooks.ts from hooks/ dir..." HOOKS=() while IFS= read -r line; do HOOKS+=("$line"); done < <(ls "$KIT_DIR/hooks/"*.sh 2>/dev/null | xargs -n1 basename | sed 's/.sh$//' | sort -u) HCOUNT=${#HOOKS[@]} echo " Found $HCOUNT hooks" cat > "$DATA_DIR/hooks.ts" <
1 && /^# / && !/^#!/ { sub(/^# */,""); gsub(/"/,"\\\""); print; exit }' "$HF" | head -c 150) [ -z "$DESC" ] && DESC="Hook in the KeiSeiKit runtime." cat >> "$DATA_DIR/hooks.ts" <> "$DATA_DIR/hooks.ts" <<'FOOTER' ]; export const HOOKS_BY_SLUG = Object.fromEntries( HOOKS.map((h) => [h.slug, h]) ); FOOTER echo " Wrote $(grep -c '^ {' "$DATA_DIR/hooks.ts") hook entries" # --- agents.ts (from manifests) --- echo "" echo "▶ Generating agents.ts from _manifests/..." AGENTS=() while IFS= read -r line; do AGENTS+=("$line"); done < <(ls "$KIT_DIR/_manifests/"*.toml 2>/dev/null | xargs -n1 basename | sed 's/.toml$//' | sort -u) ACOUNT=${#AGENTS[@]} echo " Found $ACOUNT agent manifests" cat > "$DATA_DIR/agents.ts" <
> "$DATA_DIR/agents.ts" <> "$DATA_DIR/agents.ts" <<'FOOTER' ]; export const AGENTS_BY_SLUG = Object.fromEntries( AGENTS.map((a) => [a.slug, a]) ); FOOTER echo " Wrote $(grep -c '^ {' "$DATA_DIR/agents.ts") agent entries" echo "" echo "═══ Summary ═══" echo " primitives.ts: $(grep -c '^ {' "$DATA_DIR/primitives.ts") entries" echo " skills.ts: $(grep -c '^ {' "$DATA_DIR/skills.ts") entries" echo " hooks.ts: $(grep -c '^ {' "$DATA_DIR/hooks.ts") entries" echo " agents.ts: $(grep -c '^ {' "$DATA_DIR/agents.ts") entries"