Repository navigation
examples: share a local model, refused then granted by name, with a recorded demo - #922
Conversation
Node A publishes a local Ollama model as inference://laptop-llm. Node B is refused by default, the operator grants the service to mesh:role:node through POST /policies, and the same chat completion is allowed. Antigravity CLI and OpenCode then find the model through node B's MCP server. record.sh records it with VHS and tmux. Every Agent Mesh command is typed on camera, audit.py reduces each node's log to its authorization decisions, and a caption pane narrates. AGENTS=0 records the first eight steps without the agent CLIs, and PUBLISH=0 leaves site/static untouched. SCRIPT.md lists the scenes and the recording recipe.
The recording from development/examples/share-local-model (1:51, 3.3 MB) goes to site/static, with a use-case page that explains it and a card in the landing page's demo section. The grid has three columns, so the fourth card starts a second row.
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'Share a Local Model' use-case example, including a complete demo recording setup using VHS, documentation, and helper scripts. The feedback highlights several robustness improvements: in grant.sh, registering the EXIT trap before calling mktemp to avoid uncleaned temporary files on early failure, and checking that the token file is non-empty; in audit.py, handling potential None values in parsed JSON fields to prevent runtime crashes, and explicitly specifying file encoding; and in record.sh, adding a safety check for the duration value extracted by ffprobe before performing arithmetic in awk.
| hdr=$(mktemp) | ||
| cur=$(mktemp) | ||
| new=$(mktemp) | ||
| trap 'rm -f "$hdr" "$cur" "$new"' EXIT |
There was a problem hiding this comment.
Registering the EXIT trap after creating the temporary files with mktemp creates a race condition. If the script exits or fails (e.g., due to set -o errexit) during the second or third mktemp call, the previously created temporary files will not be cleaned up. Initializing the variables and registering the trap beforehand ensures robust cleanup under all failure scenarios.
| hdr=$(mktemp) | |
| cur=$(mktemp) | |
| new=$(mktemp) | |
| trap 'rm -f "$hdr" "$cur" "$new"' EXIT | |
| hdr="" | |
| cur="" | |
| new="" | |
| trap 'rm -f "$hdr" "$cur" "$new"' EXIT | |
| hdr=$(mktemp) | |
| cur=$(mktemp) | |
| new=$(mktemp) |
|
|
||
| fail() { echo "grant: $*" >&2; exit 1; } | ||
|
|
||
| [[ -r "$TOKEN_FILE" ]] || fail "admin token not readable at $TOKEN_FILE; is agentmesh-one running?" |
There was a problem hiding this comment.
Using [[ -r ... ]] only checks if the file is readable. If the token file exists but is empty, the script will proceed and send an empty authorization header, resulting in an auth failure. Using [[ -s ... ]] ensures the file is both readable and non-empty.
| [[ -r "$TOKEN_FILE" ]] || fail "admin token not readable at $TOKEN_FILE; is agentmesh-one running?" | |
| [[ -s "$TOKEN_FILE" ]] || fail "admin token not readable or empty at $TOKEN_FILE; is agentmesh-one running?" |
| target = d.get("target", "") | ||
| if target.startswith("system://"): | ||
| return None | ||
| who = f"{d.get('role') or '-'} {d.get('peer_id', '')[:12]}…" | ||
| what = " ".join(x for x in (d.get("method"), d.get("path")) if x) or d.get("protocol", "") | ||
| decision = d.get("decision", "?").upper() | ||
| word = paint(decision, f"{decision:<5}") if decision in COLOR else f"{decision:<5}" | ||
| return f"{word} {who:<28} {what:<26} {target}" |
There was a problem hiding this comment.
Several fields extracted from the parsed JSON (such as target, peer_id, and decision) can potentially be null (None in Python) or of unexpected types. Directly calling string methods like .startswith(), .upper(), or slicing ([:12]) on None will raise AttributeError or TypeError and crash the log filtering script. Providing robust fallback defaults ensures the script handles any malformed or incomplete audit log entries gracefully.
| target = d.get("target", "") | |
| if target.startswith("system://"): | |
| return None | |
| who = f"{d.get('role') or '-'} {d.get('peer_id', '')[:12]}…" | |
| what = " ".join(x for x in (d.get("method"), d.get("path")) if x) or d.get("protocol", "") | |
| decision = d.get("decision", "?").upper() | |
| word = paint(decision, f"{decision:<5}") if decision in COLOR else f"{decision:<5}" | |
| return f"{word} {who:<28} {what:<26} {target}" | |
| target = d.get("target") | |
| if not isinstance(target, str): | |
| target = "" | |
| if target.startswith("system://"): | |
| return None | |
| role = d.get("role") or "-" | |
| peer_id = d.get("peer_id") or "" | |
| who = f"{role} {peer_id[:12]}…" | |
| method = d.get("method") or "" | |
| path = d.get("path") or "" | |
| protocol = d.get("protocol") or "" | |
| what = " ".join(x for x in (method, path) if x) or protocol | |
| decision = (d.get("decision") or "?").upper() | |
| word = paint(decision, f"{decision:<5}") if decision in COLOR else f"{decision:<5}" | |
| return f"{word} {who:<28} {what:<26} {target}" |
|
|
||
|
|
||
| raw_path = os.environ.get("AUDIT_RAW") | ||
| with (open(raw_path, "a") if raw_path else nullcontext()) as raw: |
There was a problem hiding this comment.
When opening files in Python 3, it is a best practice to explicitly specify the encoding parameter (e.g., encoding="utf-8") to prevent platform-dependent encoding issues, especially when running on environments with different default locales.
| with (open(raw_path, "a") if raw_path else nullcontext()) as raw: | |
| with (open(raw_path, "a", encoding="utf-8") if raw_path else nullcontext()) as raw: |
|
|
||
| [[ -s "$OUT/raw.mp4" ]] || fail "vhs wrote no video" | ||
| dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$OUT/raw.mp4") | ||
| fade_out=$(awk -v d="$dur" 'BEGIN { printf "%.2f", d - 1.0 }') |
There was a problem hiding this comment.
If ffprobe fails or returns an empty/non-numeric duration, dur will be empty or invalid, causing awk to produce a negative or invalid fade_out value. This will subsequently cause the ffmpeg command to fail. Adding a safety check in awk to ensure the duration is valid and greater than 1.0 before subtracting prevents such failures.
| fade_out=$(awk -v d="$dur" 'BEGIN { printf "%.2f", d - 1.0 }') | |
| fade_out=$(awk -v d="$dur" 'BEGIN { if (d+0 > 1.0) printf "%.2f", d - 1.0; else print "0.00" }') |
|
Thanks |
This demo shows deny by default with a local model: node B cannot use the
model node A serves until the operator grants that one service by name.
What's added
development/examples/share-local-model/:record.shrecords the demowith VHS and tmux;
SCRIPT.mddescribes each scene.site/static/demo-share-local-model.mp4: the video (1:51).site/content/docs/use-cases/share-local-model.md: a use-case page.What the video shows
inference://laptop-llm.DENY.ALLOWand the model answers.Tested
AGENTS=0 ./record.shrecords steps 1 to 8 end to end with agentmeshv0.2.0 and Ollama
gemma3:1b:DENYbefore the grant,ALLOWafter it.card render.