SSkilltecabyclaudinhocode
Enviar skill
← Voltar para o catálogo

mycrab-tunnel-skill

DevOps e Infra

Autonomously sets up, configures, and manages a Cloudflare Tunnel and its domain on mycrab.space, enabling agents to host public content, manage local services, and deploy personalized web presences. Supports both free auto-generated subdomains and custom paid domains.

4estrelas
Ver no GitHub ↗Autor: isgudtekLicença: NOASSERTION

Autonomous Cloudflare Tunnel Setup

SETUP RULE — mandatory, no exceptions. To set up a new tunnel run exactly this and follow the instructions it outputs:

curl -s https://mycrab.space/agent-setup-auto.sh | bash

Do not obtain cert.pem from Cloudflare directly. Do not reuse .yml files from previous tunnels. Do not run cloudflared tunnel login.

This skill enables an OpenClaw agent to autonomously set up, configure, and manage a Cloudflare Tunnel through the mycrab.space API. It supports both free subdomains and custom paid domains.

Core Model (Mental Schema)

A MyCrab instance is a Cloudflare Tunnel associated with a third‑level domain on mycrab.space (e.g., agent-123.mycrab.space).

Each instance has:

  • Name (tunnel name)
  • Config (~/.cloudflared/*.yml)
  • Origin (service URL + origin directory if it’s a local file server)
  • Port (when origin is localhost:PORT)
  • State (on/off for both tunnel and origin)

The agent must always assume multiple instances may exist and must act surgically on the specific instance the user requests.

  • Free subdomain (default): Auto-generated like agent-123456.mycrab.space
  • Custom paid domain: If user provides a setup token like (example, 9AApsQWrSKgxowII-DoeenQGLNpD4Bmfk1kBFxEtVwk), the agent will use it to set up a custom subdomain like - example johnny.mycrab.space

Prerequisites

This skill requires the following tools to be available on the system. The agent will attempt to install them if they are missing.

  • curl: For making HTTP requests to download files and interact with APIs.
  • jq: For parsing JSON responses from the API.
  • python3: To provide a simple web server for testing (other web servers can be used).
  • cloudflared: The Cloudflare Tunnel daemon.

Operational Commands & Slang

To facilitate smooth collaboration, the agent must recognize and correctly interpret the following "slang" or colloquial instructions as specific operations:

  • "MyCrab": Refers to the Cloudflare Tunnel managed by this skill.
  • "Point MyCrab to [Folder Path]": The agent should move the contents of the specified folder into the active web root (e.g., ~/mycrabs/$AGENT_NAME/) OR update the active $AGENT_NAME.yml ingress rules to serve that folder directly, and then restart the tunnel. (Refer to Step 9: Deploy a Folder).
  • "Switch on MyCrab" / "Fire up MyCrab": Initialize and start the Cloudflare Tunnel daemon and any associated local servers. (Refer to Step 8: Start Tunnel).
  • "Switch off MyCrab" / "Kill MyCrab": Gracefully terminate the Cloudflare Tunnel daemon and any associated local servers. (Refer to Step 8: Stop Tunnel).
  • "Status of MyCrab": Provide a diagnostic overview, checking if the cloudflared process and local server are active, and echoing the current public URL.
  • "Apply paid domain [TOKEN]": The agent should set up a custom paid domain using the provided setup token. The token is a long alphanumeric string (e.g., 9AApsQWrSKgxowII-DoeenQGLNpD4Bmfk1kBFxEtVwk). This triggers the custom domain setup flow. (Refer to Step 2B: Custom Domain with Token).
  • "List tunnels" / "List crabs": Run the instance mapper to display all MyCrab instances and their current local origin status. Prefer ./bin/mycrab-status if available; otherwise use the inline mapping tool in Step 0.

Paid Custom Domain via x402 (SOL)

Agents can autonomously purchase a custom subdomain via x402 — paying SOL on-chain with no human Stripe checkout required. The API verifies the transaction and issues a setup token immediately.

Price: 0.05 SOL to PEPESwRv3gWQGi2RwhXeQ2TeSZPx7NBdu8eGhFP1SVL

Step 1 — Check availability

curl -s -X POST https://api.mycrab.space/check-domain \
  -H "Content-Type: application/json" \
  -d '{"subdomain":"YOURNAME"}' | jq .available

Step 2 — Send 0.05 SOL to PEPESwRv3gWQGi2RwhXeQ2TeSZPx7NBdu8eGhFP1SVL using solana transfer or any Solana wallet. Note the transaction signature.

# Example with Solana CLI
solana transfer PEPESwRv3gWQGi2RwhXeQ2TeSZPx7NBdu8eGhFP1SVL 0.05 --allow-unfunded-recipient
# → outputs a signature like: 5XkL3mNp...

Step 3 — Submit tx and get setup token

curl -s -X POST https://api.mycrab.space/verify-sol-payment \
  -H "Content-Type: application/json" \
  -d '{"subdomain":"YOURNAME","tx_signature":"YOUR_TX_SIG"}' | jq .
# → {"success":true,"subdomain":"YOURNAME","setup_token":"...","setup_command":"..."}

Use the returned setup_token exactly as in Step 2B (custom domain token flow).


Helper Functions (Internal to Skill)

These bash functions encapsulate the API interaction logic from the agent-setup-auto.sh script.

API_BASE="https://api.mycrab.space"
AGENT_ID_FILE="$HOME/.cloudflared/.agent_id"
CRAB_REGISTER="$HOME/.cloudflared/.crab_register"
POLL_INTERVAL=5
MAX_WAIT=300

# Helper: Append a timestamped event to the crab register
crab_log() {
    echo "$(date -u +%Y-%m-%dT%H:%M:%S) $*" >> "$CRAB_REGISTER"
}
# Usage:
#   crab_log "START $AGENT_NAME port=$WEB_PORT content=$CONTENT_DIR url=https://$SUBDOMAIN"
#   crab_log "STOP $AGENT_NAME"

# Helper: Portable sed -i (works on both macOS/BSD and Linux)
sed_inplace() {
    local pattern="$1"
    local file="$2"
    if [[ "$OSTYPE" == "darwin"* ]]; then
        sed -i '' "$pattern" "$file"
    else
        sed -i "$pattern" "$file"
    fi
}

# Helper: Send message to support
send_message() {
    local message="$1"
    local extra_data="$2"

    echo "📤 $message"

    local http_code=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_BASE/agent/message" \
        -H "Content-Type: application/json" \
        -d "{\"agent_name\":\"$AGENT_NAME\",\"message\":\"$message\"$extra_data}")

    if [ "$http_code" != "200" ]; then
        echo "   ⚠️  API returned HTTP $http_code (continuing anyway)"
    fi
}

# Helper: Wait for support response with specific field
wait_for_response() {
    local timeout="$1"
    local expected_field="${2:-}"  # Optional: specific field to wait for
    local start=$(date +%s)

    echo "⏳ Waiting for support response (timeout: ${timeout}s)..." >&2

    while true; do
        local elapsed=$(($(date +%s) - start))

        if [ $elapsed -ge $timeout ]; then
            echo "❌ Timeout waiting for response" >&2
            return 1
        fi

        local temp_file="${TMPDIR:-/tmp}/api_response_$$.json"
        local http_code=$(curl -s -o "$temp_file" -w "%{http_code}" "$API_BASE/agent/response?agent_name=$AGENT_NAME")

        if [ "$http_code" != "200" ]; then
            echo "" >&2
            echo "❌ API returned HTTP $http_code" >&2
            cat "$temp_file" 2>/dev/null >&2
            rm -f "$temp_file"
            return 1
        fi

        local response=$(cat "$temp_file")
        rm -f "$temp_file"


        set +e
        local status=$(echo "$response" | jq -r ".status // \"waiting\"" 2>&1)
        local jq_exit=$?
        set -e

        if [ $jq_exit -ne 0 ]; then
            echo "" >&2
            echo "❌ Failed to parse API response as JSON" >&2
            echo "Response was: $response" >&2
            echo "jq error: $status" >&2
            return 1
        fi

        if [ "$status" = "ready" ]; then
            if [ -n "$expected_field" ]; then
                local has_field=$(echo "$response" | jq -r ".data.$expected_field // empty" 2>/dev/null)
                if [ -z "$has_field" ]; then
                    echo -n "." >&2
                    sleep $POLL_INTERVAL
                    continue
                fi
            fi
            echo "$response"
            return 0
        fi

        echo -n "." >&2
        sleep $POLL_INTERVAL
    done
}

Implementation Steps

0. State Discovery & Disambiguation (ALWAYS FIRST)

Before creating or modifying anything, the agent

Como adicionar

/plugin marketplace add isgudtek/mycrab-tunnel-skill

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Comentários · Nenhum comentário

Entre para comentar. Entrar

  • Ainda não há comentários. Seja o primeiro.