Skip to main content

Installation Guide

Save your API key once in a standard local config file, then let your own script or agent fetch the latest snapshot manifest from /api/llm/v1/snapshots/latest.
1

Save Key Locally

CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/marketscanner/llm-bundle.env"
mkdir -p "$(dirname "$CONFIG_FILE")"
umask 077
cat > "$CONFIG_FILE" <<'EOF'
MARKETSCANNER_API_KEY=PASTE_API_KEY_HERE
EOF
echo "Saved key to $CONFIG_FILE"
2

LLM Directions

Copy and paste this into your LLM:
Follow these directions:
https://gist.github.com/tlk3/31e0b091f0d2d8c1790a6067edca5fd3

My API key is already stored in the correct default location.

If I say /msr refresh, download the latest MarketScanner bundle and then reload it from disk before answering.

After refresh, work from the local bundle files unless I explicitly ask for another API call.

Do not print or expose my API key.
3

Optional Downloader Install

Optional for users who want a saved local downloader script instead of relying on /msr refresh.
#!/usr/bin/env bash
set -euo pipefail
CONFIG_FILE="${MARKETSCANNER_CONFIG_FILE:-${XDG_CONFIG_HOME:-$HOME/.config}/marketscanner/llm-bundle.env}"
if [ -f "$CONFIG_FILE" ]; then
  set -a
  . "$CONFIG_FILE"
  set +a
fi
: "${MARKETSCANNER_API_KEY:?Set MARKETSCANNER_API_KEY or create $CONFIG_FILE first}"
BASE_URL="${MARKETSCANNER_BASE_URL:-https://app.stratalerts.com}"
OUTPUT_DIR="${1:-$HOME/marketscanner-data/latest}"
mkdir -p "$OUTPUT_DIR"
MANIFEST_URL="$BASE_URL/api/llm/v1/snapshots/latest"
curl --fail --silent --show-error \
  -H "Authorization: Bearer $MARKETSCANNER_API_KEY" \
  "$MANIFEST_URL" -o "$OUTPUT_DIR/manifest.json"

extract_chunk_refs() {
  grep -o '\{[^}]*\}' "$OUTPUT_DIR/manifest.json" | while IFS= read -r obj; do
    ref="$(printf '%s\n' "$obj" | sed -n 's/.*"relative_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
    if [ -z "$ref" ]; then
      ref="$(printf '%s\n' "$obj" | sed -n 's/.*"path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
    fi
    if [ -z "$ref" ]; then
      ref="$(printf '%s\n' "$obj" | sed -n 's/.*"name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
    fi
    if [ -n "$ref" ] && printf '%s' "$obj" | grep -q '"chunk_order"\|"chunk_name"\|"symbol_count"'; then
      printf '%s\n' "$ref"
    fi
  done
}

snapshot_version="$(sed -n 's/.*"snapshot_version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$OUTPUT_DIR/manifest.json")"
chunk_refs="$(extract_chunk_refs)"
if [ -z "$chunk_refs" ]; then
  echo "No chunk references found in manifest" >&2
  exit 1
fi

while IFS= read -r ref; do
  [ -n "$ref" ] || continue
  chunk_name="${ref##*/}"
  case "$ref" in
    http://*|https://*) chunk_url="$ref" ;;
    /api/*) chunk_url="${BASE_URL%/}$ref" ;;
    *)
      if [ -n "$snapshot_version" ]; then
        chunk_url="${BASE_URL%/}/api/llm/v1/snapshots/$snapshot_version/$chunk_name"
      else
        chunk_url="${BASE_URL%/}/${ref#./}"
      fi
      ;;
  esac
  mkdir -p "$OUTPUT_DIR/$(dirname "$ref")"
  curl --fail --silent --show-error \
    -H "Authorization: Bearer $MARKETSCANNER_API_KEY" \
    "$chunk_url" -o "$OUTPUT_DIR/$ref"
done <<< "$chunk_refs"

missing=0
while IFS= read -r ref; do
  [ -n "$ref" ] || continue
  if [ ! -f "$OUTPUT_DIR/$ref" ]; then
    if [ "$missing" -eq 0 ]; then
      echo "Bundle incomplete. Missing chunks:" >&2
    fi
    echo "- $ref" >&2
    missing=1
  fi
done <<< "$chunk_refs"

if [ "$missing" -ne 0 ]; then
  exit 1
fi

chunk_count="$(printf '%s\n' "$chunk_refs" | grep -c '.')"
echo "Bundle ready: $OUTPUT_DIR"
echo "snapshot_version=${snapshot_version:-unknown}"
echo "chunk_count=$chunk_count"