Skills von pixel: artifacts-overview/SKILL.md autonomous-ai-agents/hermes-a2a devops/peer-dashboard web-content-accreation-fallback/SKILL.md
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: peer-dashboard
|
||||
description: Use when creating a peer HTML artifact on Termux/Android.
|
||||
category: devops
|
||||
---
|
||||
# Creating a Peer Dashboard
|
||||
|
||||
## Trigger
|
||||
Use when the user asks for a live dashboard showing active peer connections, updated regularly, delivered as an HTML artifact on Termux/Android.
|
||||
|
||||
## Procedure
|
||||
1. Verify VPN connectivity – run `tailscale --socket=/data/data/com.termux/files/usr/var/run/tailscaled.sock status` and confirm at least one peer is reachable.
|
||||
2. Create the daemon script – write `daemon.py` with a `tailnet()` function that calls the VPN status command, matches JSON peers to HTML rows using a two‑pass algorithm (name‑score ≥2 first pass, then unique OS match in second pass), marks the local device (`android-termux`) with `online: null` and displays "(local)" on the HTML page, and writes the result to `peers.data.json` once per minute.
|
||||
3. Write the HTML artifact – create `peer-dashboard.html` (inline CSS, dark theme, German text). The page must poll `peer_dashboard/peers.data.json` every 30 s, show live pills for VPN status, sync, and last‑check time, render a grid of peer cards with name, status badge, agent name/version, URL, latency, and consecutive failures, display a Tailnet‑Knoten table with name, IP, OS, user, and online/offline/— status, mark the local node with a “lokal” badge, and render a 24‑h timeline with 30‑min slots (green = reachable, yellow = slow >500 ms, red = offline, grey = no data), include a footer linking to the source JSON.
|
||||
4. Register the artifact – add an entry to `artifacts.json` and run `python3 gen_index.py` to update `index.html`.
|
||||
5. Start the background services –
|
||||
```bash
|
||||
python3 /data/data/com.termux/files/home/artifacts/peer_dashboard/daemon.py loop background persist_on_release true
|
||||
python3 -m http.server 8787 --bind 127.0.0.1 --directory /data/data/com.termux/files/home/artifacts background persist_on_release true
|
||||
```
|
||||
6. Open the dashboard – `am start -a android.intent.action.VIEW -d "http://127.0.0.1:8787/peer-dashboard.html"` or open via the Android browser.
|
||||
|
||||
## Pitfalls
|
||||
- Mis‑matched peers – the first fuzzy‑match may assign `android-termux` to the `pixel` peer because both contain "android". Use the two‑pass algorithm above to avoid this.
|
||||
- Local‑device leakage – if the local device appears in the JSON peer list, set its `online` to `null` and display it as "(local)" rather than letting it compete with real peers.
|
||||
- Stale HTTP server – after a session restart kill any existing `python -m http.server 8787` before starting a new one.
|
||||
- HTML lint errors – auto‑syntax check only covers .py/.json etc.; for pure HTML do a quick visual check or `node --check` on the `<script>` block.
|
||||
- **Fuzzy‑patch drift when editing daemon.py/HTML** – the patch tool's fuzzy/block‑anchor matcher can apply your hunk to a *different* code block than intended while still reporting success with a plausible diff (new text lands wrong / different block replaced). After each patch in a busy file: `grep -F` the new sentinel string and confirm the old one is gone before continuing; "success" + a clean diff is not proof the intended change landed.
|
||||
|
||||
## Always‑on rules (user preferences)
|
||||
- Dashboard text in German.
|
||||
- Dark‑theme colour palette.
|
||||
- Daemon checks every 60 s; HTML refreshes every 30 s.
|
||||
- No external resources – all assets must be in‑page or local.
|
||||
|
||||
# References
|
||||
- `references/matching-algorithm.md` – detailed two‑pass peer‑assignment algorithm and score functions.
|
||||
- `references/tailscale-commands.md` – common `tailscale` CLI invocations for this environment.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Two‑Pass Peer Assignment Algorithm
|
||||
|
||||
## Score function
|
||||
|
||||
```python
|
||||
def score(row, j):
|
||||
s = 0
|
||||
name = row["name"].lower()
|
||||
if name and name in j["hostname"]:
|
||||
s += 3
|
||||
elif j["hostname"] and j["hostname"] in name:
|
||||
s += 2
|
||||
if j["os"] and j["os"] == row["os"].lower():
|
||||
s += 1
|
||||
return s
|
||||
```
|
||||
|
||||
## Pass 1 – name‑based match (score ≥ 2)
|
||||
|
||||
1. For each HTML row, scan all remaining JSON peers.
|
||||
2. Compute `score(row, j)` as above.
|
||||
3. Pick the peer with the highest score.
|
||||
4. If `best_score ≥ 2`, mark the peer as used and attach its `online`, `last_handshake`, `version` to the row.
|
||||
5. If no peer reaches `≥ 2`, the row gets `online: null, last_handshake: null, version: ""`.
|
||||
|
||||
## Pass 2 – unique OS match (only when exactly one row and one JSON peer share the OS)
|
||||
|
||||
1. After pass 1, collect remaining open rows and JSON peers.
|
||||
2. For each row where `online` is still missing:
|
||||
* Count how many open rows have the same `os` (lower‑cased).
|
||||
* Count how many open JSON peers have the same `os`.
|
||||
* If **both counts are exactly 1**, assign that peer to that row (score ≥ 1 is sufficient).
|
||||
* Otherwise, skip the row – it will be filled with `online: null` later.
|
||||
|
||||
## Why two passes?
|
||||
|
||||
* A pure greedy name‑match can mis‑assign peers whose hostnames share substrings (e.g., `android-termux` vs `pixel`).
|
||||
* Enforcing a 1‑to‑1 OS‑match in pass 2 guarantees that a peer is only claimed when it is the *sole* candidate for that OS, preventing double‑booking and the “pixel‑slot‑theft” bug that appeared in earlier versions.
|
||||
|
||||
## Local‑device handling
|
||||
|
||||
The current device (`android-termux`) is excluded from the JSON peer pool before assignment begins. On the HTML page it is displayed with the badge `lokal` and `online: –‑` to avoid it competing with real peers.
|
||||
@@ -0,0 +1,33 @@
|
||||
# Common Tailscale CLI invocations (Termux/Android)
|
||||
|
||||
## Check status (uses local socket)
|
||||
|
||||
```bash
|
||||
tailscale --socket=/data/data/com.termux/files/usr/var/run/tailscaled.sock status
|
||||
```
|
||||
|
||||
## Bring up the local device (if not yet authorised)
|
||||
|
||||
```bash
|
||||
tailscale up --advertise-routes=100.64.0.0/10 --accept-dns=false
|
||||
```
|
||||
|
||||
## List all peers with IP, OS and labels
|
||||
|
||||
```bash
|
||||
tailscale --socket=/data/data/com.termux/files/usr/var/run/tailscaled.sock status --json | python3 -c "import sys,json; d=json.load(sys.stdin); [print(f'{k}: {v[\"addr\"]} {v[\"hostName\"]} {v[\"os\"]} {v[\"tags\"]}') for k,v in d[\"PeerMap\"].items()]"
|
||||
```
|
||||
|
||||
## Refresh lease / re‑authorise
|
||||
|
||||
```bash
|
||||
tailscale up --reset
|
||||
```
|
||||
|
||||
## Export peer data for the dashboard daemon
|
||||
|
||||
The daemon (`daemon.py`) runs:
|
||||
|
||||
```bash
|
||||
tailscale --socket=/data/data/com.termux/files/usr/var/run/tailscaled.sock status --json > /data/data/com.termux/files/home/artifacts/peer_dashboard/peers.data.json
|
||||
```
|
||||
Reference in New Issue
Block a user