home / skills / plurigrid / asi / tailscale-localsend

tailscale-localsend skill

/skills/tailscale-localsend

This skill helps you discover tailscale mesh peers and exchange files via LocalSend, enabling fast peer discovery and secure transfers.

npx playbooks add skill plurigrid/asi --skill tailscale-localsend

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
2.8 KB
---
name: tailscale-localsend
description: 'Tailscale + LocalSend Peer Discovery'
version: 1.0.0
---

# Tailscale + LocalSend Peer Discovery

Discover peers via Tailscale mesh and exchange files via LocalSend protocol.

## Architecture

```
┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│  Tailscale API  │────▶│  Peer Discovery  │────▶│  LocalSend API  │
│  (mesh network) │     │  (propagator)    │     │  (file xfer)    │
└─────────────────┘     └──────────────────┘     └─────────────────┘
```

## Discovery Flow

1. **Tailscale Status**: `tailscale status --json` → get mesh peers
2. **LocalSend Probe**: UDP multicast 224.0.0.167:53317 → find localsend-enabled peers  
3. **Intersection**: Peers on both networks get deterministic Gay.jl colors

## Usage

```bash
# Discover peers on tailscale with localsend
just ts-localsend-discover

# Send file to peer
just ts-localsend-send <peer> <file>

# Receive mode
just ts-localsend-receive
```

## Python API

```python
from tailscale_localsend import TailscaleLocalSend

tls = TailscaleLocalSend(seed=0x6761795f636f6c6f)

# Discover peers
peers = tls.discover()
# [{'name': 'macbook', 'tailscale_ip': '100.x.x.x', 'localsend_port': 53317, 'color': '#A855F7'}]

# Send file
tls.send(peer='macbook', file='data.json')

# Receive (blocking)
tls.receive(callback=lambda f: print(f"Got {f}"))
```

## Protocol Details

### Tailscale Discovery
- Uses `tailscale status --json` for mesh peers
- Extracts TailscaleIPs for each peer
- Falls back to Tailscale API if CLI unavailable

### LocalSend Protocol
- **Multicast**: 224.0.0.167:53317 (UDP)
- **Announce**: JSON with alias, fingerprint, port
- **Transfer**: REST API over HTTPS
  - `POST /api/localsend/v2/prepare-upload`
  - `POST /api/localsend/v2/upload?sessionId=...`

### Color Assignment
Each peer gets deterministic color from Gay.jl:
```python
peer_color = gay_color_at(hash(peer_fingerprint) % 1000, seed=GAY_SEED)
```

## Integration with epistemic-arbitrage

```python
from epistemic_arbitrage import ArbitrageNetwork

network = ArbitrageNetwork(seed=1069)
for peer in tls.discover():
    network.add_cell(peer['name'], knowledge=peer.get('files', 0))
    
# Propagate knowledge between peers
network.add_propagator(:peer_sync, sources, targets)
network.run_parallel(n_workers=len(peers))
```

## Commands

```bash
just ts-peers          # List tailscale peers
just ls-peers          # List localsend peers  
just ts-ls-bridge      # Bridge both networks
```

Base directory: ~/.codex/skills/tailscale-localsend

Overview

This skill integrates Tailscale mesh discovery with the LocalSend file-sharing protocol to find peers on both networks and exchange files securely. It provides CLI commands and a small Python API to discover peers, assign deterministic colors, and perform send/receive operations. The result is reliable peer discovery across VPN and local multicast domains.

How this skill works

The tool queries Tailscale (CLI or API) to list mesh peers and probes the LocalSend multicast address (224.0.0.167:53317) to find local file-sharing endpoints. It intersects both lists to identify peers reachable via either or both transports, assigns deterministic colors for UI consistency, and uses LocalSend’s REST endpoints to prepare and upload files. A simple Python class exposes discover(), send(), and receive() methods for programmatic use.

When to use it

  • Share files between machines on the same LAN and connected Tailscale mesh.
  • When you need a bridge between Tailscale-only peers and LocalSend-enabled local peers.
  • Automating peer discovery and bulk file pushes in scripts or orchestration.
  • Visualizing or grouping peers with consistent deterministic colors.

Best practices

  • Run tailscale status --json or ensure API credentials are available for reliable mesh discovery.
  • Keep LocalSend running on hosts you expect to discover; it announces via UDP multicast.
  • Use the seed parameter to stabilize color assignments across runs and UIs.
  • Validate peer fingerprints before automated transfers to prevent accidental transfers.
  • Prefer HTTPS LocalSend endpoints and confirm session IDs returned by prepare-upload before posting data.

Example use cases

  • Ad-hoc office file drops: discover nearby devices on both Tailscale and LAN and send a file without opening ports.
  • Syncing small datasets between developer laptops and a remote VM that’s on Tailscale but not directly on the same LAN.
  • Automated backups: discover a reachable peer and push logs or configuration files via a CI task.
  • Inventory and visualization: list peers, show deterministic colors, and feed them to a topology or knowledge-propagation system.

FAQ

What if tailscale CLI is not installed?

The discovery falls back to the Tailscale API if the local CLI is unavailable. Provide API credentials or run the CLI for best results.

How are colors assigned to peers?

Colors are derived deterministically from a peer fingerprint using a seeded Gay.jl color function so the same seed produces consistent colors across runs.

Is file transfer encrypted?

LocalSend’s transfer uses HTTPS endpoints for upload. Tailscale adds an encrypted mesh layer for direct mesh connections.